Output???? #include int main() { int i=43; printf("%d\n",printf("%d",printf("%d",i))); return 0;}
-
1243
-
4321
-
1234
-
4312
Reveal answer
Fill a bubble to check yourself
B
Correct answer
Explanation
printf returns the number of characters printed. Working outward: innermost printf("%d",i) prints 43 and returns 2. Middle printf("%d",2) prints 2 and returns 1. Outermost printf("%d",1) prints 1 and returns 1. The printed characters appear left-to-right: 4321. Option B correctly shows this output.
AI explanation
To determine the output of the given code, let's go through each step:
#include
int main() {
int i=43;
printf("%d\n", printf("%d", printf("%d", i)));
return 0;
}
The printf function in C returns the number of characters printed. So, let's break down the code step by step:
printf("%d", i)will print43and return2(the number of characters printed).printf("%d", printf("%d", i))will print the result of the previousprintfstatement, which is2, and return1(the number of characters printed).printf("%d\n", printf("%d", printf("%d", i)))will print the result of the previousprintfstatement, which is1, and return1(the number of characters printed).
Therefore, the output of the code will be 4321.
So, the correct answer is B) 4321.