DataType* MyVar;

This is a discussion on DataType* MyVar; within the C Programming forums, part of the General Programming Boards category; I have seen this use of code for the Declare Statement: Code: char* MyVar; I have been told this is ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Auburn, AL
    Posts
    2

    Question DataType* MyVar;

    I have seen this use of code for the Declare Statement:
    Code:
     char* MyVar;
    I have been told this is equivalent to:
    Code:
     char *MyVar;
    Is one "Old School" or what? I question because none of the three books Microsoft C, Borland C 3.0, or "Teach Yourself C" says anything about the first example. Are they both allowed in ANSI C?

    Do they behave differently if you initialize one with a value?
    Thank You,
    Troy

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,641
    The whitespace is not significant here, so you can even write it as:
    Code:
    char * MyVar;
    char* tends to be more of a C++ convention.
    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
    Jan 2006
    Location
    Auburn, AL
    Posts
    2

    Cool char* myvar, secondvar;

    If the white space is truely insignificant then in the following example:
    Code:
    char* myvar, secondvar;
    myvar is a pointer & secondvar is type char?
    Or, does the whitespace matter in this example and cause the secondvar to be a pointer also?

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Whitespace is insignificant you could even write
    Code:
    char*charptr,a_char,*another_charptr; /* no spaces at all*/
    Kurt
    Last edited by ZuK; 01-30-2006 at 12:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global arrays shared between multiple source files
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 08-14-2008, 06:29 PM
  2. implicit/explicit? conversion of classes?
    By what3v3r in forum C++ Programming
    Replies: 7
    Last Post: 01-31-2006, 06:08 PM
  3. beginner question
    By davidnj732 in forum C Programming
    Replies: 2
    Last Post: 02-17-2003, 08:45 PM
  4. Purpose of pointers?
    By Yawgmoth in forum C Programming
    Replies: 9
    Last Post: 12-16-2002, 05:14 PM
  5. Exactly what is a static int?
    By Shadow12345 in forum C++ Programming
    Replies: 8
    Last Post: 05-25-2002, 06:21 PM

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