what is the value of b
if a=5;
b=++a + ++a
Answer Posted / invader007
The output will be 14.
i.e. The the value of b is 14.
Explanation:
Consider Expression (b = ++a + ++a;)
Initially the value of a is 5. After the first pre increment operator it will be 6 and after second one it becomes 7. So we guess the expression evaluated as (b = 6 + 7 i.e. b = 13). But wait... In C Programming Language ++a is nothing but a = a + 1, am I right? Ofcourse it's right. Now consider the presedense of pre increment operator over addition operator, Compiler first's evaluate both ++a and the perform addition. So first ++a evaluated to 6 i.e. Now a = 6 then second ++a evaluated as 7 i.e. Now a = 7 and overwrite the old value of a. So compiler evaluated our expression as
b = (a = a +1) + (a = a+1); first compiler assign a = 6 and then a = 7 so our expression becomes b = 7 + 7 as same variable can't holds two different values at a time. And finally our main out will be 14.
I hope now you understand it.
Thnk you!
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why c is called free form language?
What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.
What is static identifier?
Is fortran still used in 2018?
Explain about the functions strcat() and strcmp()?
What is difference between stdio h and conio h?
Write a programme using structure that create a record of students. The user allow to add a record and delete a record and also show the records in ascending order.
Explain what header files do I need in order to define the standard library functions I use?
what is the role you expect in software industry?
What is the size of structure in c?
Why do we use stdio h and conio h?
Why is c so powerful?
difference between native and cross compilers
Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc...xyz in s2 . Allow for letters of either case and digits, and be prepared to handle cases like a-b-c and a-z0-9 and -a-z. z-a:zyx......ba -1-6-:-123456- 1-9-1:123456789987654321 a-R-L:a-R...L a-b-c:abbc
Explain what is the benefit of using #define to declare a constant?