Thread: Pointer Mock Exam Question

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by spadez
    isnt *p defining p as a pointer.
    Not quite. Consider the syntax for defining a pointer and initialising it to be a null pointer:
    Code:
    int *p = NULL;
    Notice that the type name int is part of the syntax. Compare it to this dereferencing of p to print what the pointer points to:
    Code:
    printf("%d\n", *p);
    Now, the type name of the pointed to type is not part of the syntax.
    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

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by spadez View Post
    I find this slightly confusing, isnt *p defining p as a pointer. In which case how is *p "dereferencing the pointer". I might need this dumbing down a little :s
    Another reason I dislike T * syntax...
    You can also define pointers as:
    T* p;
    Which might make it clearer.
    Even clearer is:
    T* p1;
    T* p2;
    Instead of:
    T *p1, *p2;

    p2 belongs to the same line as the declaration, hence it is also a declaration. Merely putting "*p" somewhere does not mean you are declaring a new variable since there's no type before it. Instead it's dereferencing the pointer.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a pointer to a function question..
    By transgalactic2 in forum C Programming
    Replies: 17
    Last Post: 10-21-2008, 11:47 AM
  2. Question about pointer arithmetic and types
    By brooksbp in forum C Programming
    Replies: 4
    Last Post: 08-22-2008, 01:53 PM
  3. Exam Question - Possible Mistake?
    By Richie T in forum C++ Programming
    Replies: 15
    Last Post: 05-08-2006, 03:44 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. general pointer & malloc question
    By jstn in forum C Programming
    Replies: 2
    Last Post: 05-14-2002, 09:51 AM