निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
What will be the output of the following code snippet?
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
printf("%d%d", i, j);
}
}
A)
B)
C)
D)
Explanation:
Let's break down the given code snippet:
Code:
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
printf("%d%d", i, j);
}
}
Explanation:
- Outer loop (over
i
): Runs 3 times (fromi = 0
toi = 2
). - Inner loop (over
j
): Runs 2 times for each iteration ofi
(fromj = 0
toj = 1
). - The
printf
prints the values ofi
andj
in the formati j
without spaces.
Let's go through the iterations:
- When
i = 0
,j
will take values0
and1
, so the output will be00
and01
. - When
i = 1
,j
will take values0
and1
, so the output will be10
and11
. - When
i = 2
,j
will take values0
and1
, so the output will be20
and21
.
Thus, the final output will be: 0001 1011 2021
.
Correct Answer:
(B) 000110112021.