Thread: precedence question

  1. #1
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463

    precedence question

    I read this in a book.

    Code:
    apple = sizeof (int) * p;
    I tested the code and found out that it's sizeof integer multiplied by p. Can you some explain the precedence order of this?

    thanks alot.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What's confusing? All you are doing is multiplying the size of an integer by the value of p. There's no precedence order confusion here. What else could it possibly be? All you are doing is taking two things, multiplying them, and assigning that value some place.


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

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    sizeof has higher precedence than multiplication operator.
    So the exp is equivalent to
    apple = (sizeof(int)) * p;
    Guess what will be the value of :
    apple = sizeof p * p; // don't forget to init p to some vale
    Last edited by Bayint Naung; 08-10-2010 at 11:37 PM.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It doesn't matter in what order multiplication is done in. Why the confusion?
    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
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    OP is probably thinking: apple = sizeof (int) * p as
    apple = sizeof( (int) *p); // say p is pointer to say (char)
    which you need to know precedence.

    If I'm not wrong, is it from Expert C Programming book?
    Last edited by Bayint Naung; 08-10-2010 at 11:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question bout my work
    By SirTalksAlots in forum C Programming
    Replies: 4
    Last Post: 07-18-2010, 03:23 PM
  2. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 05:24 AM
  3. SDL buffer channels question
    By TriKri in forum Game Programming
    Replies: 3
    Last Post: 12-09-2009, 05:52 PM
  4. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 06:24 AM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM