Figure out the output of code ...

This is a discussion on Figure out the output of code ... within the C Programming forums, part of the General Programming Boards category; I'm having trouble with this assignment which I'm supposed to show what the output would be for this code: Code: ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    17

    Figure out the output of code ...

    I'm having trouble with this assignment which I'm supposed to show what the output would be for this code:
    Code:
    int x=1;
    int y=2;
    int z=3;
    
    printf("%d %d\n", 3 | 6, 3 || 6);
    
    printf("%d %d\n", 6 >> 1, 6 << 1);
    
    printf("%d %d\n", 10 & 3,10 && 3);
    I'm confused because x, y, nor z is in any of the printf statements...
    Am I missing something?

    Thank you for any help

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Newworld
    I'm having trouble with this assignment which I'm supposed to show what the output would be for this code:
    Code:
    int x=1;
    int y=2;
    int z=3;
    
    printf("%d %d\n", 3 | 6, 3 || 6);
    
    printf("%d %d\n", 6 >> 1, 6 << 1);
    
    printf("%d %d\n", 10 & 3,10 && 3);
    I'm confused because x, y, nor z is in any of the printf statements...
    Am I missing something?

    Thank you for any help
    Well we don't really do your homework for you, what's the fun of that? Besides, you could always just compile it and run it!

    Break it down into pieces:

    3 | 6 == what?
    3 || 6 == what?
    6 >> 1 == what?
    6 << 1 == what?

    See a pattern here yet?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Watch for flying houses. Nessarose's Avatar
    Join Date
    Sep 2004
    Posts
    46
    If that's the assignment, then you're right, the variables x, y and z have no use being there. In fact if you compile this with "gcc -Wall" it tells you:

    Code:
    $ gcc -Wall test.c 
    test.c: In function `main':
    test.c:6: warning: unused variable `x'
    test.c:7: warning: unused variable `y'
    test.c:8: warning: unused variable `z'

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    17
    Well we don't really do your homework for you, what's the fun of that? Besides, you could always just compile it and run it!
    I understand that, what I meant to ask was where are x, y, and z being used it this code?

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Is that the entire homework question, or are they used elsewhere? It could be they're like those word problems:

    "If John is traveling from Chicago, and Mark is traveling from New York, where is Seattle?"

    Where they give you useless information to confuse you.

    Either that or you've only posted part of the code in question, and they're being used in some code you haven't shown us.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    17
    Is that the entire homework question, or are they used elsewhere? It could be they're like those word problems:

    "If John is traveling from Chicago, and Mark is traveling from New York, where is Seattle?"

    Where they give you useless information to confuse you.

    Either that or you've only posted part of the code in question, and they're being used in some code you haven't shown us.
    That is the entire code. I guess I will have to email my professor because everything I gave you is what is exactly what is given to me.

    edit:
    Assuming there is no typo and x,y,z are just useless info, then the output would just be:
    7 1
    3 12
    2 1
    Last edited by Newworld; 09-19-2004 at 11:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't figure out what's with this code
    By silverstein101 in forum C++ Programming
    Replies: 8
    Last Post: 04-16-2008, 01:45 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 02:30 PM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 02:29 PM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21