What is the output? int i=7 printf("%dn",i++*i++);

This question is related to Wipro Interview

Showing Answers 1 - 75 of 176 Answers

kiruthiga

  • Feb 2nd, 2006
 

49

  Was this answer useful?  Yes

Perri sona college

  • Mar 5th, 2006
 

Compiler dependent

  Was this answer useful?  Yes

Anil Kumar

  • Mar 9th, 2006
 

ans is : 56n

  Was this answer useful?  Yes

Sharique Qamar

  • Oct 13th, 2006
 

This question contains "code side effect".

Bcoz according to K & R , a single variables value can't be within one expression.

  Was this answer useful?  Yes

Soumya

  • Feb 5th, 2007
 

The answer is 56 because the compiler will use right to left associtavity here..
and when it gets i++
then for the value of i,
nothing happens..
then it gets *,
it puts it in stack..
then gets another i++
by this time the 1st ++ is executed and i's value is 8 now..
so it will be 8*7=56

purushottam

  • Oct 16th, 2011
 

49n

  Was this answer useful?  Yes

sourabh

  • Nov 7th, 2011
 

49

  Was this answer useful?  Yes

Md Moin Khan

  • Nov 11th, 2011
 

An output device is any piece of computer hardware equipment used to communicate the results of data processing carried out by an information processing system (such as a computer) to the outside world.

In computing, input/output, or I/O, refers to the communication between an information processing system (such as a computer), and the outside world. Inputs are the signals or data sent to the system, and outputs are the signals or data sent by the system to the outside.
Examples of output devices:

ex
Speakers
Headphones
Screen (Monitor)
Printer

  Was this answer useful?  Yes

nidul

  • Nov 13th, 2011
 

8*8=64

i++=7+1;
i++=7+1;
i++*i++=8*8=64

  Was this answer useful?  Yes

renuka

  • Nov 22nd, 2011
 

56n

  Was this answer useful?  Yes

akash

  • Jan 22nd, 2012
 

I think 72 but it will depend on comiler

  Was this answer useful?  Yes

Pallavi Bhosale

  • Jan 25th, 2012
 

Ans wil be: 63

sakshi

  • Feb 1st, 2012
 

error...
int i=7
needs a semicolon at the end

madhu

  • Mar 15th, 2012
 

72n

  Was this answer useful?  Yes

Nikhil

  • Mar 20th, 2012
 

56

  Was this answer useful?  Yes

mahamad

  • Apr 15th, 2012
 

Its 49n because compiler starts execution from right to left then it founds that ++i (remember,this is compiler execution) means it will take just 7 simply then again it founds that ++i (remember,this is compiler execution).
If u have any doubt then try the below code
int i=7;
printf("%d",++i*++i);
it will be 81
try it my friends!

  Was this answer useful?  Yes

The result will vary based on compiler and optimization settings, and in general is not predictable. The order of evaluation of expressions and the order in which side effects are applied is *unspecified*; you could get the result of 7*7, 7*8, or some other value. The language standard specifically calls this out as *undefined behavior*, so *any* result can be considered "correct". You should never write code like this.

  Was this answer useful?  Yes

aisha

  • Sep 7th, 2012
 

56

  Was this answer useful?  Yes

nagesh

  • Dec 18th, 2012
 

56 bcoz ++ operator precedence is right to right.......

  Was this answer useful?  Yes

samantha

  • Apr 9th, 2013
 

i++=8
i++*i++=64

  Was this answer useful?  Yes

makesh

  • Jul 19th, 2013
 

Answer is: 49.
Because when I value leaves printf it gets incremented because its right ++(incremented)

  Was this answer useful?  Yes

wilson paul

  • Aug 27th, 2013
 

56

  Was this answer useful?  Yes

venugopal

  • Nov 1st, 2013
 

64

  Was this answer useful?  Yes

trisha biswal

  • Jan 11th, 2014
 

8*7=56

  Was this answer useful?  Yes

vikash kumar

  • Jan 15th, 2014
 

8*7

  Was this answer useful?  Yes

Bash

  • Sep 3rd, 2014
 

49

  Was this answer useful?  Yes

shailee

  • Sep 12th, 2014
 

7,64

  Was this answer useful?  Yes

Santhosh K

  • Sep 12th, 2014
 

i=7
so i++ * i++
7*7
49

  Was this answer useful?  Yes

priya

  • Dec 27th, 2014
 

error

  Was this answer useful?  Yes

Mrinal

  • Jan 12th, 2015
 

56
explanation:
i=7
i++ * i++
8 * 7 (after reading right most "i" the value gets incremented to 8, as we know that printf() reads from right.

  Was this answer useful?  Yes

estuti

  • Mar 5th, 2015
 

got the same question in my exam... the answer is very weird..should be 51..checked it on compiler. also

  Was this answer useful?  Yes

jfbode

  • Mar 8th, 2015
 

@estuti - if you took an exam that claimed this kind of an expression gave a specific, well-defined result, then the professor who wrote the exam doesn't understand how the language works. Any expression of the form x++*x++ invokes undefined behavior, and the result will vary based on platform, compiler settings etc.

  Was this answer useful?  Yes

Pradeep

  • Mar 23rd, 2015
 

Brother it is post increment

  Was this answer useful?  Yes

Sagar

  • Apr 20th, 2015
 

Initially i=7,
in printf statement (i++*i++)==>(7*8)=56
Finally, i turns to 9 (As simple as we are incrementing the i value twice the value turns to 9)

per-increment example:
int i=7;
printf(++i*++i)==> (8*9)=72
finally the value of i will be 9

  Was this answer useful?  Yes

Jagan

  • May 30th, 2015
 

8*9=72

  Was this answer useful?  Yes

Balakumar

  • Jul 15th, 2015
 

56

  Was this answer useful?  Yes

komal

  • Jul 19th, 2015
 

56

  Was this answer useful?  Yes

gaurav jain

  • Sep 16th, 2015
 

Answer is 56

  Was this answer useful?  Yes

Rupesh Ranjan

  • Sep 19th, 2015
 

63, its working something like that (i++*++i) = (7*9).
now your question is that why so? Because at first part of equation i++ = its 8 but not for itself its for another ++i = 9(because first it will take the incremental value of i = 8 and then increment it by 1 then its actual value if 9). and if in place of i++ is ++i and if in place of ++i is i++then the answer is 64 . Because same ++i = 8 and the i++=8 .++i is pre increment operator and i++ is post increment operator.

Code
  1. #include<conio.h>

  2. void main()

  3. {

  4. int i  = 7;

  5. printf("%d",i++*++i);

  6. getch();

  7. }

  8.  

  Was this answer useful?  Yes

priya

  • Oct 9th, 2015
 

56n is correct ans

  Was this answer useful?  Yes

tejaswini

  • Oct 31st, 2015
 

56

  Was this answer useful?  Yes

Sara

  • Nov 7th, 2015
 

Answer will be an error

  Was this answer useful?  Yes

swathi priya

  • Dec 8th, 2015
 

Depends upon the type of compiler, because different parsing differs in different compilers.

  Was this answer useful?  Yes

kale Vilas

  • Feb 12th, 2016
 

Error

  Was this answer useful?  Yes

rajesh

  • Mar 1st, 2016
 

i++=7 (print first then it will updated as 8)
*
i++=8 (print first then it will updated as 9)
=7*8=>56

  Was this answer useful?  Yes

MalathiPalsamy

  • Mar 21st, 2016
 

56

  Was this answer useful?  Yes

ditikrushnagiri

  • Apr 22nd, 2016
 

correct one is 56

  Was this answer useful?  Yes

Rohini

  • Jul 18th, 2016
 

56

  Was this answer useful?  Yes

Sandra

  • Sep 11th, 2016
 

Actually the result is undefined.
Compiler cant find undefined errors

  Was this answer useful?  Yes

Ashwini

  • Jan 23rd, 2017
 

64

  Was this answer useful?  Yes

i++*i++ where i=7
post increment in this first use the value the update the variable
so first keep i=7 then increment its now i=8, this new value use by right is as use value, after its increment as 9
so expression is 7*8= 56 and after this instruction i value is 9.

  Was this answer useful?  Yes

Bhavana Vutla

  • Sep 26th, 2019
 

56n

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions