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 email@example.com. 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 37
- Output of C programs | Set 46
- Output of C++ programs | Set 42
- Output of C programs | Set 65 (If-Else)
- Output of C++ programs | Set 44
- Output of C programs | Set 41
- Output of C programs | Set 42
- Output of C programs | Set 43
- Output of C++ programs | Set 40
- Output of C programs | Set 45
- Output of C programs | Set 55
- Output of C++ programs | Set 45
- Output of C programs | Set 48
- Output of C programs | Set 51
- Output of C programs | Set 52