Thread: my final questions i am new to c++

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    2

    my final questions i am new to c++

    1. printf("%d", 10*5/10); what is this result?

    2. printf("%d", 10+5-5); what is this result?

    3. a=d++ +(b=a); a=4,b=4,d=4 a=?

    4. c=a+ a++ - b--; a=4,b=4 c=?

    5. c=a+ ++a - b--; a=4,b=5 c=?

    6. if(a==0 && b==0) printf("1);
    else
    if(a==0 && b==0) printf("2");
    else printf("3");

    (if a=1 and b=0) what is the result?
    (if a=0 and b=0) what is the result?
    (if a=0 and b=1) what is the result?

    please help me thanks regards...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    1. printf("%d", 10*5/10); what is this result?
    Zero

    2. printf("%d", 10+5-5); what is this result?
    Also Zero

    3. a=d++ +(b=a); a=4,b=4,d=4 a=?
    If you've got a compiler, try it.

    4. c=a+ a++ - b--; a=4,b=4 c=?
    5. c=a+ ++a - b--; a=4,b=5 c=?
    http://cboard.cprogramming.com/showt...ined+behaviour

    6. dunno, bored of doing your homework.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Also Zero
    O_o

    Okay...

    Ignore operator precedence, ignore operator associativity, ignore the fact that we are apparently discussing C or C++, how in the world are you getting zero for that?

    Soma

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I was thinking the same thing...
    I was also thinking why printf is used when it's C++...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > how in the world are you getting zero for that?
    Because I couldn't give a rats ass whether the cross-forum spammer, who is too lazy to even fire up the compiler and actually punch out 5 lines of code to get the answer, either learns to think for themselves, or performs a drone-like copy of whatever is posted and subsequently fails.

    I could have written
    Also zero
    but that might have tipped them off.

    So long as someone doesn't blurt out 42 (or the other right answer), then all will be well I suppose.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    2
    please help me i dont know how to use complier...

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by svetlana6167 View Post
    please help me i dont know how to use complier...
    if this is for a class, that is usually the first thing they teach you.

    if not. Please let us know what platform for which you are trying to write this code (windows/unix/linux/mac/etc.) and what set of development tools you are using (msvc, gcc, sun, intel, etc) and we will try to help you out.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oh... my... goodness...
    The first thing to do when learning C/C++ is to get a compiler and editor/IDE.
    Don't expect to write code without compiling it.

    And even though you were told, you continue posting on both forums. That is why they call you a cross-forum spammer.
    Ask your question in one forum, only.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > please help me i dont know how to use complier...
    Well that should have been your first question then!.

    As Elkvis says, if you want useful help, provide details.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Kung Fu Kitty Angus's Avatar
    Join Date
    Oct 2008
    Location
    Montreal, Canada
    Posts
    115
    Quote Originally Posted by Elysia View Post
    Oh... my... goodness...
    The first thing to do when learning C/C++ is to get a compiler and editor/IDE.
    Don't expect to write code without compiling it.
    Don't presume that the way you were taught is the way that everyone is taught. Especially when you consider from what country someone named "Svetlana" whose first language clearly isn't English might be.

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Angus View Post
    Don't presume that the way you were taught is the way that everyone is taught. Especially when you consider from what country someone named "Svetlana" whose first language clearly isn't English might be.
    I've heard of theory-intensive computer science classes where you think about what the computer might do, but that's frankly ridiculous for an intro to programming course.

  12. #12
    Kung Fu Kitty Angus's Avatar
    Join Date
    Oct 2008
    Location
    Montreal, Canada
    Posts
    115
    Not ridiculous, but it is beyond "very disciplined". The way they run their universities in the FSU makes it seem like they were setup by captured SS officers. I'll never forget my Russian complex variables prof. What a Nazi!

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Angus View Post
    Don't presume that the way you were taught is the way that everyone is taught. Especially when you consider from what country someone named "Svetlana" whose first language clearly isn't English might be.
    If taught already, then shame on the one.
    If not taught already, then one should heed the advice and get a compiler and IDE/editor to compile and test all subsequent code.
    Good advice.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Someone who asks questions like 4 and 5 probably doesn't know any better. I mean, ask this once but twice!!

    So you don't have a compiler and are asked meaningless questions as if they meant something...
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  15. #15
    Kung Fu Kitty Angus's Avatar
    Join Date
    Oct 2008
    Location
    Montreal, Canada
    Posts
    115
    Quote Originally Posted by Elysia View Post
    If taught already, then shame on the one.
    If not taught already, then one should heed the advice and get a compiler and IDE/editor to compile and test all subsequent code.
    Good advice.
    Even if advice that presumes someone's environment and facilities available can be good, it doesn't address the OP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  4. Studying for Final, Couple Questions...
    By stewade in forum C Programming
    Replies: 4
    Last Post: 05-10-2004, 05:02 PM
  5. The Final Time for this questions
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 01-16-2002, 04:59 AM