ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
void main()
{
            int i=5;
            printf("%d",i+++++i);
}
 Question Submitted By :: Surenda Pal Singh Chouhan
I also faced this Question!!     Rank Answer Posted By  
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 1
Compiler Error 

Explanation:
The expression i+++++i is parsed as i ++ ++ + i which is an 
illegal combination of operators.
 
Is This Answer Correct ?    2 Yes 0 No
Surenda Pal Singh Chouhan
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 2
the condition is like i++ + ++i 

so 5 + 6 =11
 
Is This Answer Correct ?    2 Yes 3 No
Guest
 
 
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 3
error: invalid lvalue in increment
 
Is This Answer Correct ?    1 Yes 1 No
Basha
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 4
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 ?    1 Yes 0 No
Visu
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 5
This statement is just i=i++ + ++i;
Initially i=5
i++ increments after the statement completed For now its 
value is 5.
++i increments before its execution.so it is 6
It executes like
i=5+6; i.e. i=11
 
Is This Answer Correct ?    0 Yes 1 No
Sulochana
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 6
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 ?    1 Yes 0 No
Visu
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 7
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 ?    0 Yes 0 No
Jaroosh
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 8
Error
 
Is This Answer Correct ?    1 Yes 0 No
Suresh Reddy
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 9
:) its just how the Compiler parses things..

the..maximum matching (of a token) principle... from the 
left..

1. i++ is a valid maximum match. Good, next
2. + match, next (expects a + or a identifier,for furthur 
match)
3. + (this is not a identifier, but a + will do so: 
match=++). Next the parser wants an indentifier.. else 
compiler flags an error..
4. + (not an identifier.. so.. fails)
 
Is This Answer Correct ?    0 Yes 0 No
Vinay,
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 10
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 ?    1 Yes 0 No
Sheetal
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 11
i think it will give a compilation error..
 
Is This Answer Correct ?    0 Yes 0 No
Shruti
 
  Re: void main() { int i=5; printf("%d",i+++++i); }
Answer
# 12
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 ?    0 Yes 0 No
Vamsi
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Consider a language that does not have arrays but does have stacks as a data type.and PUSH POP..are all defined .Show how a one dimensional array can be implemented by using two stacks. Google3
what is a c-language.what is do. HCL3
Given an unsigned integer, find if the number is power of 2?  3
Program to write some contents into a file using file operations with proper error messages.  1
Design a program using an array that lists even numbers and odd numbers separately from the 12 numbers supplied by a user.  7
Program to trim a given character from a string. NetApp4
find second largest element in array w/o using sorting techniques? use onle one for loop. Zycus-Infotech2
Write a program to compute the following 1!+2!+...n!  3
Write a program to compare two strings without using the strcmp() function Accenture14
program to find middle element of linklist? Huawei1
what is disadvantage of pointer in C Tech-Mahindra5
How do you write a program which produces its own source code as its output?  3
palindrome for strings and numbers----Can anybody do the prog? TCS6
Result of the following program is main() { int i=0; for(i=0;i<20;i++) { switch(i) case 0:i+=5; case 1:i+=2; case 5:i+=5; default i+=4; break;} printf("%d,",i); } } a)0,5,9,13,17 b)5,9,13,17 c)12,17,22 d)16,21 e)syntax error IBM4
macros and function are related in what aspect? a)recursion b)varying no of arguments c)hypochecking d)type declaration HCL8
Why does not use getgh(); and <conio.h> in c language. Elofic2
what is the use of pointers  5
What are volatile variables?  1
why should i select you? Wipro18
What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1; TCS10
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com