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 6757133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:36:35+00:00 2026-05-26T13:36:35+00:00

when I declare C++ variables, I do it like this: int a,b,c,d; or string

  • 0

when I declare C++ variables, I do it like this:

int a,b,c,d;

or

string strA,strB,strC,strD;

I.e., first the type then a comma separated list of variable names.

However, I declare pointers like this:

int *a,*b,*c,*d;

and references like this:

int &a,&b,&c,&d;

To be consistent it should be

int* a,b,c,d;

and

int& a,b,c,d;

Why is it not consistent?

  • 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-05-26T13:36:36+00:00Added an answer on May 26, 2026 at 1:36 pm

    It’s because of the C heritage. The * modifier applies to the variable in C. So the C++ designers made & to apply to the variable as well by analogy, since they couldn’t change the first without breaking C compatibility. Same is true for the array syntax too:

    int anInt, *aPointerToInt, anArrayOfInt[100];
    

    In The Design and Evolution of C++ Bjarne Stroustrup says he wasn’t happy with this but had to accept it for C compatibility. He was unhappy with this in particular:

    int *a[10];
    

    It’s not clear from the declaration if a is a pointer to an array or an array of pointers (it’s an array of pointers, you need brackets to override).

    Of course, you can always use a typedef to clean things up a little.

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

Sidebar

Related Questions

When I declare a enum variable like this: enum paint_colors { RED, GREEN, BLUE,
In VB.Net, I can declare a variable in a function as Static, like this:
If you declare variables of type byte or short and attempt to perform arithmetic
Why is it bad practice to declare variables on one line? e.g. private String
I've always wondered this - why can't you declare variables after a case label
I want to declare two types of variables in for's init-statement. like the following
For example i have a string input int,can i declare a variable base on
First off I'd like to say this is the only java experience I've had.
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
I've seen some variable declare in VB.net in several way like: print(dim _Foo as

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.