Hi somebody can help me to understand what this code does
tanks...
Code:void main() { int a; printf("%d", a); }
Hi somebody can help me to understand what this code does
tanks...
Code:void main() { int a; printf("%d", a); }
It is poorly written to begin with. A better example:
In which case you should read up on what printf does if you cannot tell what the program does.Code:#include <stdio.h> int main(void) { int a = 123; printf("%d\n", a); return 0; }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The first one is liable to set off ICBMs, cause military drones to fire hellfire missiles at your house, or possibly just print some garbage values (if you're lucky), due to undefined behavior
Laserlight is showing a good example.
The "main" line, is opening up the main program. You need this to run any program.
The "int a" is declaring an integer. You need to declare things as integers, floating numbers, characters, etc. for you to use them later on.
now, the "printf" line is trying to print to your monitor a demical integer (that's what the %d is for) and the number it is looking for is assigned to that "a" integer you declared earlier.
Unfortunately, the a variable was never set, so you won't be able to output anything.
Try compiling and running laserlight's program. You should see an output of "123". that's because the declared value of "a" is 123. You could change this to whatever you want, and call upon it with printf.
Good luck and happy coding
the code will print some garbage value as the variable 'a' is not initialized, ie. it does not contain any value at the time it is being used by printf().
Code:void main() { int a; printf("%d", a); }