What is The Output of the following program? #include<stdio.h>void main(){int i = printf("00"); int i =printf("00"); printf("%d",i);}000002Garbage value
Question
What is The Output of the following program? #include<stdio.h>void main(){int i = printf("00"); int i =printf("00"); printf("%d",i);}000002Garbage value
Solution
The code you've provided is written in C language. However, it contains a syntax error. You are declaring the variable 'i' twice.
Here is the corrected version of your code:
#include<stdio.h>
void main(){
int i = printf("00");
printf("%d",i);
}
The printf function returns the number of characters printed. So, in this case, it prints "00" and returns 2 (the number of characters printed).
So, the output of the corrected program will be:
002
It first prints "00" from the printf("00"), then it prints "2" from the printf("%d",i); because 'i' holds the value 2 which is the number of characters printed by the previous printf statement.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.