Need some explaination here pleased | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Need some explaination here pleased

whats that sequence of numbers you get when you try to output or perform an operation on a variable that wasn't assigned a value? e.g #include <iostream> using namespace std; int main(){ int j ; cout << j; return 0; } if you run this code you would get like this sequence of randum numbers

14th Dec 2017, 4:32 AM
Mind To Machine 💻🕆
Mind To Machine 💻🕆 - avatar
4 Answers
+ 2
you will get random no.s in term of programming languages it is termed as garbage value..
14th Dec 2017, 5:16 AM
shashank singh
shashank singh - avatar
+ 3
if you have a undefined variable it is given a random value of whatever data happens to be on the stack in the place the compiler decided that variable should go interpreted as an integer or a double. It will usually be the same each time you run the program but can be different depending on your code and may differ if using a different compiler. You should gave your variables a value so that this doesn't happen
14th Dec 2017, 4:49 AM
Mooaholic
Mooaholic - avatar
+ 1
when you declare a variable, you assign a space to be used by the program. and if you dont initiaize (assign a value) to that variable, it will have the value which happens to be at the space occupied by your variable.
14th Dec 2017, 5:05 AM
storm
storm - avatar
+ 1
To add to this discussion, the number will be initialized to zero if you define it outside of main. Globally defined variables are usually assigned to default values instead of the 'garbage' values when defining them in local scopes.
14th Dec 2017, 5:49 AM
Zeke Williams
Zeke Williams - avatar