+ 4

Explain this code in this output?

#include <stdio.h> int main() { int a=1; int b; b=a; printf ("%d",--a+b--); return 0; }

4th May 2020, 5:56 AM
Nithish
Nithish - avatar
4 ответов
+ 1
Nithish a = 1 b = a it means b = 1 So --a will be 0 and b-- will be 1 --a+b-- = 0 + 1 = 1 Note - --a is pre-decrement - here first decrement the value by 1 then assign b-- is post-decrement - here first assign the value then decrement the value by 1
4th May 2020, 6:28 AM
A͢J
A͢J - avatar
+ 3
Thanks AJ
4th May 2020, 6:43 AM
Nithish
Nithish - avatar
+ 1
The answer is 1. Explain about this
4th May 2020, 5:57 AM
Nithish
Nithish - avatar
+ 1
In this code a is initialised to 1 and b is equal to 1 as a is assigned to b Now coming to print statement --a + b-- In this above expression --a // pre-decreament therefore first a gets decremented and used in the expression i.e a=0 is used But in the case of b-- //post-decreament therefore first value of b is used in the expression and then decrements i.e b=1 is used Hence result will be 0 + 1 = 1 //Ans= 1
22nd May 2020, 2:01 PM
Rasik Raikar
Rasik Raikar - avatar