What will be the output of the following C code?#include <stdio.h> void main() { int x = 10; int y = x++ + 20; printf("%d,%d",x,y); return 0; }
Question
What will be the output of the following C code?#include <stdio.h> void main() { int x = 10; int y = x++ + 20; printf("%d,%d",x,y); return 0; }
Solution
The output of the given C code will be "11,30".
Here's the step by step explanation:
-
The variable
xis initialized with the value10. -
The expression
x++ + 20is evaluated. Here,x++is a post-increment operation which means the value ofxis used first and then it is incremented. So,x++gives10and thenxbecomes11. Adding20to10gives30. This result30is stored in the variabley. -
The
printffunction prints the values ofxandywhich are11and30respectively.
So, the output is "11,30".
Similar Questions
what will be the output of the c program?
What will be the output of the following code?
What will be the output of the following C++ code?
What will be the output of the following program?
What will be the output of the following C code?#include <stdio.h>int main() { int i; for (i = 0; i < 5; i++); printf("%d\n", i); return 0;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.