Thread: Declaring a pointer.

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    8

    Declaring a pointer.

    What is the right way to declare a pointer and assign it an existing variable in the same line?

    would this:
    Code:
    int *p = &e;
    be the same as:
    Code:
    int *p;
    p = &e;
    ?

    Thank you very much for your patience.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes, they have the same net effect of making p point to e.
    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
    Oct 2011
    Posts
    8
    Thank you laserlight!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Declaring pointer to variable in struct
    By movl0x1 in forum C Programming
    Replies: 5
    Last Post: 07-09-2007, 11:24 AM
  2. Declaring a pointer, int *ptr vs int ptr
    By thetinman in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2006, 02:39 PM
  3. Declaring a Pointer (quick question)
    By viciousv322 in forum C Programming
    Replies: 4
    Last Post: 12-16-2005, 11:27 AM
  4. declaring function pointer types for callbacks
    By Pea in forum C Programming
    Replies: 6
    Last Post: 01-06-2005, 09:46 PM
  5. What's the use of declaring a pointer to void ?
    By Nutshell in forum C Programming
    Replies: 2
    Last Post: 01-15-2002, 05:00 AM