C++ Pointers

Posted on 2007-10-09
Last Modified: 2013-12-14
This is a fairly simple question but I just want to make sure. Do char* c char * c and char *c all mean the same thing or are they different?
Question by:jmf8883
    LVL 45

    Accepted Solution

    Hi jmf8883,

    They are the same.  C/C++ are very friendly with regard to optional spacing.  Use whatever looks right to you.

    Good Luck,
    LVL 86

    Assisted Solution

    Yes, thed indeed mean the same, you can even omit the spaces completely.

    Author Comment

    LVL 10

    Expert Comment

    Yes, they all mean the same syntactically - however, from a human semantics point of view, they often don't!

    For example, one often sees something like this:

    1. char *p;

    2. *p = ...

    Here, in '1', *p declares a pointer to a character.

    in '2' *p IS a char.

    So, if I said to you what's *p what would you say?

    Now consider:

    1. char * p;

    2. *p = ...

    In '1' we now have '*<>p' which at least gives a hint that, as in '2', *p is different, i.e., we use white-space to *help* ourselves and others to note that the two are not the same - in the first notation, *p/*p look the same, but are different, in'2' * p/*p might show those who are less savy that something's not quite the same.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now