निम्नलिखित कोड का परिणाम क्या है:
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)
B)
C)
D)
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
x
andy
are set to1
. -
z = x++ + y:
x++
is the post-increment operator. It uses the current value ofx
(which is1
), and then incrementsx
by 1.- So,
z = 1 + 1
results inz = 2
, and after this,x
becomes2
due to the post-increment.
-
printf("%d, %d", x, y):
- After the post-increment,
x
is2
andy
remains1
.
- After the post-increment,
Thus, the output is:
Correct Answer:
(A) 2,1