Computer Science, asked by archanajha93040, 2 months ago

What will be the output of the following statements? int i=3,i printf(% dº%d",I,I++)​

Answers

Answered by anindyaadhikari13
3

Corrected Co‎de:

int i = 3;

printf("%d %d", i, i++);

The Output:

>> 3 3

Explanation:

  • Here, the initial value of the variable 'i' is 3.
  • At first, the value of 'i' is displayed which is 3. Then, the value of 'i' is post-incremented. So, it remains same. Therefore, 3 is printed again. Now, the value of 'i' becomes 4.
  • However, if it was ++i instead of i++, the output would be - 3 4.

Know More:

There are two types of increment/decrement operations.

  1. Post increment/decrement.
  2. Pre increment/decrement.

Post Increment/Decrement – Here, operation takes place first and then the value is incremented/decremented.

Example –

> int a = 2;

> int b = a++;

> b = 2

Now, a = 3.

Pre Increment/Decrement – Here, value is first increment/decrement and then the operation is carried out.

Example –

> int a = 2;

> int b = ++a;

> b = 3

Also, a = 3

Similar questions