+ 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; }
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
+ 3
Thanks AJ
+ 1
The answer is 1.
Explain about this
+ 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