Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:07:46+00:00 2026-06-17T06:07:46+00:00

Possible Duplicate: Declaring pointers; asterisk on the left or right of the space between

  • 0

Possible Duplicate:
Declaring pointers; asterisk on the left or right of the space between the type and name?

I’ve always been wondering what’s the exact correct position to put * and &. it seems that C++ is pretty tolerant about where to put these marks.
For example I’ve seem pointer and ampersand been put on both left and right of a keyword or in the middle of two keywords, but confusingly sometimes they seems to mean the same thing, especially when used together with const

void f1(structure_type const& parameter)
void f2(structure_type const &parameter)

void f2(structure_type  const *sptr);
void f2(structure_type  const* sptr);
void f2(structure_type  const * sptr);

The examples are not exhaustive. I see them everywhere while being declared or been passed to a function. Do they even mean the same thing? But I also see cases while putting * will affect which object being referred as a pointer (likely the case where * is in between two keywords).

EDITED:

int const *Constant
int const * Constant // this above two seem the same to me, both as pointer to a constant value
int const* Constant //  EDIT: this one seems the same as above. instead of a constant pointer

const int * Constant // this is also a pointer to a constant value, but the word order changed while the pointer position stays the same, rather confusing.

int* const Constant
int * const Constant // instead, these two are constant pointers

So I concluded this:

T const* p; // pointer to const T
const T* p  // seems same from above
T* const p; // const pointer to T

Still, this confused the hell out of me. Doesn’t the compiler care about position and the spacing required for them?

Edit:
I want to know in general of the position matters. If yes in what cases.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:07:47+00:00Added an answer on June 17, 2026 at 6:07 am

    White space matters only to the degree that it keeps tokens from running together and (for example) creating a single token, so (for example) int x is obviously different from intx.

    When you’re dealing with something like: int const*x;, whitespace on either size of the * makes absolutely no difference to the compiler at all.

    The difference between a pointer to const int and const pointer to int depends on which side of the * the const is on.

    int const *x;    // pointer to const int
    int *const x;    // const pointer to int
    

    The primary difference is readability when/if you define/declare multiple objects in the same declaration.

    int* x, y;
    int *x, y;
    

    In the first, somebody might think that x and y are pointers to int — but in fact, x is a pointer to an int, and y is an int. To some people’s eyes, the second reflects that fact more accurately.

    One way to prevent any misinterpretation is to only ever define one object at a time:

    int *x;
    int y;
    

    For any of these, correct interpretation is fairly easy if you ignore whitespace entirely (except to tell you where one toke ends and another starts, so you know “const int” is two tokens) and read from right to left, reading * as “pointer to”. For example: int volatile * const x; is read as “x is a const pointer to a volatile int”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Declaring pointers; asterisk on the left or right of the space between
Possible Duplicates: Declaring pointers; asterisk on the left or right of the space between
Possible Duplicate: Difference between declaring variables before or in loop? I always wondered, is
Possible Duplicate: What’s the difference between “Array()” and “[]” while declaring a JavaScript array?
Possible Duplicate: In C, what is the correct syntax for declaring pointers? When I
Possible Duplicate: In C, what is the correct syntax for declaring pointers? Correct C
Possible Duplicate: In C, what is the correct syntax for declaring pointers? I am
Possible Duplicate: In C, what is the correct syntax for declaring pointers? In C++
Possible Duplicate: Declaring Multiple Variables in JavaScript I was wondering whether there is a
Possible Duplicate: Difference between declaring variables before or in loop? Is there any (or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.