Click here to Skip to main content
13,191,642 members (71,340 online)
Rate this:
 
Please Sign up or sign in to vote.
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 1-Jul-11 20:44pm
Awa_tcp415
Updated 4-Jul-11 6:05am
Joan M91.7K
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
SAKryukov 2-Jul-11 3:17am
   
Absolutely, a 5.
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Try to debug this code. That will help you understand what is really happening.
  Permalink  
Comments
SAKryukov 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..
SAKryukov 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Output:
function returned with the value of "7"
  Permalink  
Comments
Awa_tcp 2-Jul-11 3:14am
   
Hi

It is returning "7" to whom .

thanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171017.2 | Last Updated 4 Jul 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100