What is this output?

This is a discussion on What is this output? within the C++ Programming forums, part of the General Programming Boards category; a= 5 , b = 6 a = (b++) + 3; c = 2*a + (++b); d = 2 * ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    45

    What is this output?

    a= 5 , b = 6


    a = (b++) + 3;

    c = 2*a + (++b);

    d = 2 * (++c) - (a++);


    What are the values?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    Try to reason out the answers then put those statements into a program and see the output for yourself.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    45
    Quote Originally Posted by laserlight View Post
    Try to reason out the answers then put those statements into a program and see the output for yourself.

    My program isn't working right now and I don't know what to do. What is the output can someone help me?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    Quote Originally Posted by xbusterx
    My program isn't working right now and I don't know what to do.
    Fix it. What is your current program?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    Quote Originally Posted by xbusterx View Post
    My program isn't working right now and I don't know what to do. What is the output can someone help me?
    what do you think it should be?
    Tell us and we may tell you whether you're right...

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    45
    Quote Originally Posted by xbusterx View Post
    a= 5 , b = 6


    a = (b++) + 3;

    c = 2*a + (++b);

    d = 2 * (++c) - (a++);


    What are the values?

    a = 10, c = 27 ?, dunno what d is

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Can you produce the steps that you come to that conclusion from? [hint: I think it's wrong, I think I know WHERE you are going wrong, but it's much easier to explain what you are doing wrong if you actually show the individual steps of your calculation].

    --
    mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by xbusterx View Post
    a = 10, c = 27 ?, dunno what d is
    Can you tell me what you think the difference is between:
    Code:
    b++;
    ++b;
    Because it seems you mix those two up. I think your answers would be correct if you mix those up .

  9. #9
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Why do you declare a = 5, then later a = (b++) + 3 o.O?
    Currently research OpenGL

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by Akkernight View Post
    Why do you declare a = 5, then later a = (b++) + 3 o.O?
    I don't think the input is under his control.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 03:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 06:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM

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