10 10 10 10 10
Here, it would seem that, as ‘i’ got assigned a value 10, so the loop will run only one time because the loop condition will fail as ‘i’ becomes 11 the next time it enters the loop. But the output is quite different than what we expected. The reason behind this is the scope of variable is within the method. As soon as the loop exits , i is counted according to i of for loop which makes the condition true upto 5 times (0-4). See scope rules for more details.
Here, the loop runs according to the ‘i’ declared outside the loop, and hence it will run five times and the ‘i’ inside the loop will be printed five times.
x and i are Equal
As x and i are equal in value, the if condition satisfies and prints “x and i are equal”.
Note: In C this same program will produce a compile-time error as, static variables are load time entity while auto variables are run-time entity and we can not initialize any load time variable by the run time variable.
GEEKS size = 6 GEEKS length = 5
sizeof() function returns the size of the string including null character while strlen() function returns length of the string excluding null character.
With the help of extern keyword, the declaration of variable can be done any where in the program. Here, i is a variable which is being declared after the printf statement outside the main. Still, it can be accessed by the printf statement as it is an extern variable. For more details on the keyword extern
As, %o is used to print the number in octal number format and %x is used to print the number in hexadecimal number format. And if we convert decimal 10 to octal , we get 12 and in hexadecimal it will give a
Geeks For Geeks is the best
Instead of getting output as Geeks\nFor\nGeeks\nis\nthe\nbest, the output is something different. %s treats \n as ‘new line’ even if it is inside a string.
This article is contributed by Mazhar Imam Khan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Output of C Programs | Set 1
- Output of C Programs | Set 2
- Output of C Programs | Set 3
- Output of C Programs | Set 4
- Output of C Programs | Set 5
- Output of C Programs | Set 6
- Output of C Programs | Set 7
- Output of C Programs | Set 9
- Output of C Programs | Set 11
- Output of C Programs | Set 12
- Output of C Programs | Set 14
- Output of C Programs | Set 13
- Output of C Programs | Set 16
- Output of C++ programs | Set 50
- Output of Java Programs | Set 12
- Output of Java programs | Set 10 (Garbage Collection)
- Output of C++ programs | Set 21
- Output of Java programs | Set 13 (Collections)
- Output of C programs | Set 30 (Switch Case)
- Output of C++ programs | Set 22