Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Hi all.
Please tell me what will be output with explanation.

#include "stdio.h"

main ( )
{
   int x = 2, y = 5;
  if (x < y) 
    return (x = x+y);
  else
    printf ("z1");
    printf("z2");
}


Thanks.
Posted
Updated 4-Jul-11 6:05am
v3

You've been asked this as a homework question. You can also just compile and run it to find the output and use the debugger to 'explain' it. We don't do homework for people who won't even try.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Jul-11 3:17am    
Absolutely, a 5.
--SA
Try to debug this code. That will help you understand what is really happening.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Jul-11 3:18am    
I cannot believe it may happen :<
--SA
Awa_tcp 4-Jul-11 1:02am    
It's not just a question ?...

I know the answer but there is something interesting ....

say to whom it is returning
the value..
Sergey Alexandrovich Kryukov 5-Jul-11 0:25am    
Sorry if you feel my comment was harsh. I did not know that you knew the answer.

The problem is so trivial that I think a person who does no know the answer could have trouble using debugger -- I know that from my experience with others.

If you knew the answer -- sorry for suspecting you did not -- this is the different story. In this case -- why asking it? To share something interesting? But there is nothing interesting in it. It does not teach anything at any level. Redundant "if" (result of the check statically known), no sense -- is that interesting? I don't think so.

Sorry,
--SA
Output:
function returned with the value of "7"
 
Share this answer
 
Comments
Awa_tcp 2-Jul-11 3:14am    
Hi
It is returning "7" to whom .

thanks
it will return 7 to operating system... under the control of that O.S ( this program would be running))....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900