Thread: what will be the output?

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    33

    what will be the output?

    Can any one explain me the output of the following program?
    Code:
    #include<studio.h>
    #define foo(x,y) x+y
    into foo(int x,int y);
    main(){
    Print("%d",foo(5,3));
    }
    into foo(into x, int y)
    {
    return x*y;
    }

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    The output will be nothing since it doesn't compile due to multiple errors/typos/brainos.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    The Canada man is right! However, the indentation is also something you should take in great consideration.
    Let's try to debug a bit.
    Code:
    #include<studio.h>                  <-- It's stdio.h. It is composed from standard and input-output
    
    #define foo(x,y) x+y                <-- I do not see the reason of existence of this
    
    into foo(int x,int y);                 <-- It is int, not into!
    
    main()                                    <-- We use to write int main(void)
    {
        Print("%d",foo(5,3));           <-- It is printf, not print
    /* Here we use to write return 0, in order to show that the code executed as we planed to. */
    }
    into foo(into x, int y)                  <-- It is int, not into!
    {
          return x*y;
    }
    Give it another shot.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    Registered User
    Join Date
    Feb 2013
    Location
    Sweden
    Posts
    89
    Correct all the typos and other faults (you already got suggestion for those), compile and run. Then you know what will be the output…
    The next step would probably be to figure out why…
    I suspect that the #define thing could mess things up for the compiler, though…

    Tried to correct the code myself and compile it, and as long as the #define is there, gcc refuse to compile it. Why? Probably, to begin with, because the line ”int foo(int x, int y)” will be replaced with something like ”int int x+int y” by the pre-compiler, and that doesn't make much sense to me at least…

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    you guys probably just gave the OP all the answers to this homework assignment.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    144
    this is definitely a homework question.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You've no idea how often we get a thread with literally this exact title.
    Personally I've learnt to ignore them. Ask a compiler the answer instead.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    Aug 2012
    Posts
    33
    Quote Originally Posted by bos1234 View Post
    this is definitely a homework question.
    Lol...how do you know ..??

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513

    For the OP: A sample post that might receive better advice

    I ran the following program and did not get the result I expected.

    Code:
      /*
        This is where you put the actual code that you compiled, making sure
        correct spelling and syntax are observed.
        Also ensure the code is indented properly!
      */
    I thought that the output should be [GUESS], but instead it's printing [RESULT]. The reason I think it should be [GUESS] is because [the reasoning you used to arrive at your guess, by thinking about the problem before asking the question on a forum]. Can someone explain why this might be wrong?

  10. #10
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    ^^ You still probably won't get a direct answer when posting like this, but people are more likely to take your problem seriously and offer helpful advice that will lead you to the answer you're looking for.

  11. #11
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Matticus View Post
    I ran the following program and did not get the result I expected.

    Code:
      /*
        This is where you put the actual code that you compiled, making sure
        correct spelling and syntax are observed.
        Also ensure the code is indented properly!
      */
    I thought that the output should be [GUESS], but instead it's printing [RESULT]. The reason I think it should be [GUESS] is because [the reasoning you used to arrive at your guess, by thinking about the problem before asking the question on a forum]. Can someone explain why this might be wrong?
    Deserves to be sticky
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying input to output K&R there is no output
    By amadeus111 in forum C Programming
    Replies: 5
    Last Post: 02-24-2013, 05:09 AM
  2. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 08:26 AM
  3. How to edit output in struct and call for the output
    By andrewkho in forum C Programming
    Replies: 4
    Last Post: 03-16-2010, 10:28 PM
  4. terminal output not showing output properly
    By stanlvw in forum C Programming
    Replies: 13
    Last Post: 11-19-2007, 10:46 PM
  5. Replies: 3
    Last Post: 02-19-2003, 08:34 PM