What will be the output of the following statements? int i=3,i printf(% dº%d",I,I++)
Answers
Answered by
3
Corrected Code:
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.
- Post increment/decrement.
- 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
History,
1 month ago
Computer Science,
1 month ago
Science,
1 month ago
Social Sciences,
2 months ago
English,
2 months ago
Science,
10 months ago
Chemistry,
10 months ago