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
A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler
What is meant by 'bit masking'?
What are the 5 types of inheritance in c ++?
Explain null pointer.
What is clrscr in c?
What is the difference between āgā and āgā in C?
Difference between malloc() and calloc() function?
Which is better oop or procedural?
How can I send mail from within a c program?
Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]
Explain the binary height balanced tree?
Is it possible to initialize a variable at the time it was declared?
What is a program flowchart and explain how does it help in writing a program?
Explain that why C is procedural?
What are the disadvantages of external storage class?