Declaring a Pointer (quick question)

This is a discussion on Declaring a Pointer (quick question) within the C Programming forums, part of the General Programming Boards category; what is the correct way to declare a pointer? I've looked it up and i think that the correct way ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    37

    Declaring a Pointer (quick question)

    what is the correct way to declare a pointer?

    I've looked it up and i think that the correct way is

    Code:
    int *ptr;
    however i am also seeing

    Code:
    *ptr
    both of these are answers for this multiple choice question

    the choices are:

    Code:
    a.  int_ptr x;
    b.  int *ptr
    c.  *int ptr;
    d. *ptr;

  2. #2
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >a. int_ptr x;
    Only if int_ptr is a typedef:
    Code:
    typedef int *int_ptr;
    int_ptr x;
    >b. int *ptr
    This is correct, but you need to add a semicolon to terminate the statement.

    >c. *int ptr;
    That's a syntax error.

    >d. *ptr;
    This isn't a declaration, it's an expression that dereferences an existing pointer. Separate issue entirely.

    Cheers!

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    Is there an e. None of the above?
    If you understand what you're doing, you're not learning anything.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    Or even "I think it's this answer", how am I doing?
    The last person to post their entire multiple choice questionaire got well and truly roasted.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    Salem: you mean like this? (I appreciate the point your making, but no need flamin' 'em when they don't deserve it!)

    Quote Originally Posted by viciousv322
    I've looked it up and i think that the correct way is

    Code:
    int *ptr;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 04:20 AM
  2. Pointer question
    By rakan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 02:23 AM
  3. Quick Pointer question
    By Sentral in forum C++ Programming
    Replies: 3
    Last Post: 05-14-2006, 08:36 PM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 04:36 AM
  5. Simple pointer question
    By jayznz in forum C Programming
    Replies: 2
    Last Post: 04-05-2006, 12:36 AM

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