Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What is the right type to use for boolean values in c?

988


Explain what is wrong with this program statement?

1067


Write the control statements in C language

1127


Which programming language is best for getting job 2020?

983


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

1015


What type of function is main ()?

995


What is scope rule in c?

1010


When should structures be passed by values or by references?

994


what is bit rate & baud rate? plz give wave forms

1913


Design a program which assigns values to the array temperature. The program should then display the array with appropriate column and row headings.

2275


What is union in c?

1059


What is a buffer in c?

946


Write program to remove duplicate in an array?

1025


Explain how does flowchart help in writing a program?

1060


What does malloc () calloc () realloc () free () do?

1001