निम्नलिखित कोड का परिणाम क्या है:
What is the output of the following code:
#include<stdio.h>
int main(){
int x=1, y=1,z;
z=x++ +y
printf("%d, %d",x,y);
A
2,1
B
1,2
C
1,1
D
0,2
Explanation
The given C code contains the following:
#include
int main(){
int x=1, y=1, z;
z = x++ + y;
printf("%d, %d", x, y);
}
Explanation:
-
x = 1, y = 1: Initially, both
xandyare set to1. -
z = x++ + y:
x++is the post-increment operator. It uses the current value ofx(which is1), and then incrementsxby 1.- So,
z = 1 + 1results inz = 2, and after this,xbecomes2due to the post-increment.
-
printf("%d, %d", x, y):
- After the post-increment,
xis2andyremains1.
- After the post-increment,
Thus, the output is:
Correct Answer:
(A) 2,1
Correct Answer: A) 2,1