Knowee
Questions
Features
Study Tools

What is The Output of the following program? #include<stdio.h> void main() { int i = printf("00"); int i =printf("00"); printf("%d",i); } 0 00 002

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);

}

0 00 002

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be "002". Here's why:

  1. The printf function returns the number of characters printed. So, when you do int i = printf("00");, it prints "00" and returns 2 (the number of characters printed), which is then stored in i.

  2. However, you have a duplicate declaration of i in the same scope, which is not allowed in C. So, the program should actually give a compile error.

But if we assume that the second declaration of i is a mistake and ignore it, then the printf("%d",i); will print the value of i, which is 2.

So, the output will be "002".

This problem has been solved

Similar Questions

What is the output of the following C Program?

What is the output for the following code?

What is the output of the following Java program?

What will be the output of the following C++ code?

What is the output of the following code in Python?

1/4

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.