New course! Every coder should learn Generative AI!
Try a free lesson+ 1
can someone explain this ? how it works ?
#include <iostream> #include <cmath> using namespace std; int main() { int i; for(int i=0;i<0;i++){ } cout<<i; } //output CodeBlocks7208852 //output SoloLearn 8
5 Answers
+ 2
It's a garbage value nothing else int i =0 is clearly out of scope from the outside scope. Whenever you try to print something or do some operation on some variables which are defined but never initialized compiler is free to crash at that moment.
In practice, they tend to just have some nonsensical value(garbage) in there initially - some compilers may even put in specific, fixed values to make it obvious when looking in a debugger - but strictly speaking, the compiler is free to do anything from crashing to summoning a pokemon.
To avoid getting that 0 just initialize that i with 0 at starting.
+ 5
The compiler is free to do anything from crashing to summoning a pokemon
- Yugabdh 2019
+ 1
Flaming Arrow xD
Make it quote
Make it viral
Put it on fire
0
You can even generate the same by
int main()
{
int i;
int x= 0;
cout<<i;
}
//output SoloLearn 8
Clearly speaking its a garbage value that's it
0
Thanks