Thread: Review for Test

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    31

    Review for Test

    I'm studying for an exam, so hopefully someone can clarify some things for me. Thought I'd post everything under one thread, instead of making a new one for every question that comes up. I typed up a list of precedence levels and this is what I've got so far.

    unary - +
    arithmetic operators * / % - +
    relational operators < > <= >=
    logic operators && ||
    bitwise operators ~ & ^ |

    I'm not sure where >> and << go.

    I found this list on some site, but it doesn't include bitwise operators.

    ( ) [ ] -> .
    ! ~ - * & sizeof cast ++ -
    * / %
    + -
    < <= >= >
    == !=
    &
    ^
    &&
    ||
    ?: (right->left)
    = += -= (right->left)
    , (comma)

    Thanks in advance!
    You guys have been so helpful!! All the little things I've overlooked or ignored are starting to make sense
    Last edited by arrgh; 05-06-2008 at 03:01 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I'm not sure where >> and << go.
    They are bitwise operators.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    31
    But which has greater precedence? For example:
    Code:
    i >> ~j ^ k
    Would this be (i >> (~j)) ^ k or i >> ((~j) ^ k)?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It would be equivalent to: (i >> (~j)) ^ k
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Rather than trying to remember the precedence of everything, I would recommend using parenthesises to explicitly specify what goes first and in what order, because even if you do remember for the test, you will most likely forget at later dates.
    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.

  6. #6
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Why they had to follow the precedence ?
    Would not it be more apt just to do it from left to right?

    5 + 4 * 2 = 18

    Edit: I mean, why language designers use precedence!

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by manav View Post
    Why they had to follow the precedence ?
    Would not it be more apt just to do it from left to right?

    5 + 4 * 2 = 18

    Edit: I mean, why language designers use precedence!
    Becuase the mathematicians set up rules about the order of precedence, and computer people (in the beginning) were often of a mathematical/engineering background, so they followed the same principle. But you are right, there is no absolute need for it. Simple calculators tend to NOT have operator precedence, you have to explicitly use parenthesis (or the "M" buttons) and such.

    --
    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
    Apr 2008
    Posts
    31
    If you declare a variable extern inside a function, then the variable has static storage duration, but still has a block scope, so is there a way to change the scope of a variable within a function?

  9. #9

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Review required for program of date difference
    By chottachatri in forum C Programming
    Replies: 6
    Last Post: 10-31-2008, 11:46 AM
  2. My Web site.. Please review..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 08-11-2003, 08:00 AM
  3. Exam Review?
    By NinetyFourGirl in forum C++ Programming
    Replies: 4
    Last Post: 06-18-2002, 03:45 PM
  4. Can someone review?
    By ob1cnobe in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 09:48 PM