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


Please Help Members By Posting Answers For Below Questions

how should functions be apportioned among source files?

627


‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

1879


differentiate built-in functions and user – defined functions.

628


Write a program to swap two numbers without using third variable?

814


Why C language is a procedural language?

623






A set of N billiard balls are set on a one-dimensional table. The table is 1 meter long, set north-south with two pockets at either side. Each ball has zero width and there is no friction so it is moving with a fixed velocity of either northward or southward and bounces back in a perfect elastic collision from other balls it encounter on its way (or drop into one of the pockets). Your job is to keep track of the balls movements. Task Please write a program that gets the initial place, speed and direction of all the balls and gives the position of a specific ball after t seconds. Input The first line contains the number of scenarios. Each one of the other lines in the input contains a scenario: The first number, N, is the number of balls; followed by N pairs of numbers: the distance in centimeters from the south end of the table and the speed (positive speed meaning it moves northward); the last two numbers are the number i of the target ball you should track and the time T in seconds. Output The output is a single number for each line which is the place (distance in centimeters from the south end of the table) of the tracked ball after T seconds. Note: There is no new line character at the end of the result. Sample Input 5 1 50 1 1 1000 1 50 1 1 6 1 60 -2 1 6 2 10 1 95 -1 2 30 2 10 1 95 -1 2 60 Sample Output 100 56 48 65 70

2134


Is there a built-in function in C that can be used for sorting data?

744


What is wrong in this statement?

606


Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

610


What is a keyword?

747


What is a pointer variable in c language?

645


How do I get an accurate error status return from system on ms-dos?

649


Describe dynamic data structure in c programming language?

604


What are the types of assignment statements?

630


Define the scope of static variables.

606