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...


void main()
{
int i=5;
printf("%d",i+++++i);
}

Answers were Sorted based on User's Feedback



void main() { int i=5; printf("%d",i+++++i); } ..

Answer / visu

i+++++i=i++ + ++i
remember this expression is nothing but adding two i's

now unary operators hav higher precedence than binary
=>++ executes first
so i++ =5 (since value changes after statement)
and ++i makes it i=6

as i said its jus adding to i's
now ans=i+i=6+6=12

Is This Answer Correct ?    15 Yes 5 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / surenda pal singh chouhan

Compiler Error

Explanation:
The expression i+++++i is parsed as i ++ ++ + i which is an
illegal combination of operators.

Is This Answer Correct ?    17 Yes 9 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / basha

error: invalid lvalue in increment

Is This Answer Correct ?    8 Yes 3 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / jaroosh

This is a very interesting issue, to solve this, first you
have to note an interesting thing about pre and
postincrementation operators :
a) postincrementation operator instantly MAKES variable an
RVALUE in expression, this is because postincrement operator
doesnt keep track of how many postincrements were made so it
is NOT cumulative (ie u can only use one postincrementation
for variable)
b) preincrementational operator first increments variable
and THEN uses it in expression so there is no need to keep
track of how many preincrementations were made thus
preincrement is cumulative.
Following lines make the point :
i++ = 1; //WRONG! i++ becomes RVALUE,you cannot assign to it
++i = 1; //OK! you first incremented and then assigned.
and thus :
i++++; //WRONG! (i++) is RVALUE so you cannot (RVALUE)++
++++i; //OK! ++(++i)
Now, since postfic ++ has the higher precedence, :
i+++++i
is treaded like :
(i++)++ + i
which will throw compiler error.
i++ + ++i
is however fine, so as
i+ ++++i

This issue might be compiler specific, Im not sure.

Is This Answer Correct ?    5 Yes 2 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / sheetal

gives error
"error C2105: '++' needs l-value"
because it parses above expression in "((i++)++)+i), so in
2nd unary operator it searches for l-value.
If we modify above pgm into following way:-
void main()
{
int i=5;
printf("%d",((i++)+(++i)));
}
it will give answer 12.
because once last pre-unary increment operator is operated,
i is incremented to 6 and 6+6 = 12.
if we put one more print for i's value, it will give i =7.
because first post-increment operator is operated after
first printf statement as follows.
void main()
{
int i=5;
printf("%d",((i++)+(++i)));
printf("%d\n",i); // ===> i =7
}

Is This Answer Correct ?    4 Yes 1 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / visu

hey sulochana hav u tried it in a compiler..
cuz for me the result for that is 12.

i+++++i might give u an error but for sure (i++ + ++i)=12

Is This Answer Correct ?    7 Yes 5 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / suresh reddy

Error

Is This Answer Correct ?    2 Yes 1 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / vamsi

Hi Guys.....

The answer is

6+6 = 12

The compiler will take the expression as
i++ + ++i
And the expression would be evaluated from Right to left ...

so answer is 12 and i=7;

Is This Answer Correct ?    1 Yes 0 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / pramod

ERROR! Left Operand must be an LVALUE

Is This Answer Correct ?    1 Yes 0 No

void main() { int i=5; printf("%d",i+++++i); } ..

Answer / mukul garg

i=5;
i++ + ++i;
5+7=12
ans:12

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

what is c language?

2 Answers  


what is the use of call back function in c?tell me with example

2 Answers   Bosch,


Can we compile a program without main() function?

0 Answers  


a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

0 Answers   Wilco,


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers  


Write a C Program to display the following menu: Menu 1. Display 2. Copy 3. Append 4. Exit Accept the choice (1-4) from the user, and perform the following tasks: Choice 1: Accept a file name from the user and display the file on screen Choice 2: Accept two file names, and copy first file to the second Choice 3: Accept two file names, and append second file to the first file Choice 4: Terminate the program

1 Answers   Accenture, Concor, DMU, Satyam, Syntel, Tora,


related proverb of "dont count your chicken before it hatches"

1 Answers  


Can you please explain the difference between syntax vs logical error?

0 Answers  


What are pointers?

0 Answers   Accenture, Tavant Technologies, Zensar,


Explain how do you use a pointer to a function?

0 Answers  


Explain what does a function declared as pascal do differently?

0 Answers  


Define macros.

0 Answers   Tech Mahindra,


Categories