Thread: "int (x*)[5];" Could anyone tells me what's the type of x?

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    16

    "int (x*)[5];" Could anyone tells me what's the type of x?

    "int (x*)[5];"
    Is x a pointer to "int ...[]"?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by hchingwong
    Is x a pointer to "int ...[]"?
    Yes, x is a pointer to an int[5].
    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
    Dec 2009
    Posts
    16
    Thank you laserlight.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Oh wait, I'm sorry. I misread. Actually, that should result in a compile error. I was thinking of:
    Code:
    int (*x)[5];
    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
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by laserlight View Post
    Oh wait, I'm sorry. I misread.
    Reading your first post, I was shocked why didn't I see this type of pointer syntax before. and was about to search the internet for it.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    16

    Cool

    X seems like a pointer point to an integer array that contain 5 members.
    Because complier give me an warning: "assignment from incompatible pointer type" in this case.
    Code:
    int (*x)[5];
    int b[3];
    x = &b;
    And this one pass without warning.
    Code:
    int b[5];
    This's the first time I ask a question on the forum. So,
    thank you everybody.

  7. #7
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by hchingwong View Post
    X seems like a pointer point to an integer array that contain 5 members.
    Because complier give me an warning: "assignment from incompatible pointer type" in this case.
    Code:
    int (*x)[5];
    int b[3];
    x = &b;
    And this one pass without warning.
    Code:
    int b[5];
    This's the first time I ask a question on the forum. So,
    thank you everybody.
    Code:
    int (*x)[5];
    Here x is a pointer pointing to an array having 5 ints. So, when you do this
    Code:
    int b[3];
    x=&b;
    You're assigning x to an array having 3 ints which is contrary to your declaration of x. That's why you get warning.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  8. #8
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by hchingwong View Post
    X seems like a pointer point to an integer array that contain 5 members.
    Because complier give me an warning: "assignment from incompatible pointer type" in this case.
    Code:
    int (*x)[5];
    int b[3];
    x = &b;
    If you really wanted to, you could finagle something like
    Code:
    int (*x)[5];
    int b[3];
    x = (int (*)[5]) &b;

  9. #9
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Identifier Type-- int

    Name/Pointer--------- (x*) /*Can be a name or pointer to said type( this is needed to help set up the compiler to set up memory constraints */

    Space/Memory used -------------[5] /* how much memory should the compiler set aside. If not initialized, then this must be assigned later or malloc must be used for the pointed to memory address */



    Try this on for size:


    Code:
    typedef int (*pfunc)(void);
    pfunc Foo;

    Typedef
    Last edited by slingerland3g; 12-07-2009 at 02:26 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM