The output of the following ‘C’ language code is: void main() { int x=1, i,…
2017
The output of the following ‘C’ language code is:
void main()
{
int x=1, i, y=2;
for(i=0;i<10;i++)
{
x << 1;
y=x+i;
}
printf("%0d,%0d",x,y);
}
- A.
10,11
- B.
1,1
- C.
10,1
- D.
1,10
Attempted by 454 students.
Show answer & explanation
Correct answer: D
The code initializes x = 1 and y = 2. Inside the loop, the expression x << 1; shifts bits left but does not assign the value back to x (it lacks =). Thus, x remains 1 throughout. In the final iteration (i = 9), y = x + i becomes 1 + 9 = 10.
Output: 1,10 (Option D).