Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When declaring a pointer, VS automatically moves the asterisk to the pointer's type

When I try to declare a pointer in VS 2019, the asterisk automatically moves to the pointer's type side. I know this works too, but it bugs me.

// How it shows:
int* number1{};

// How i want it to show: 
int *number2{};

Is there a way I can change that?

like image 482
nicalaia Avatar asked Dec 30 '19 22:12

nicalaia


People also ask

What is the correct way of declaring a pointer and using it?

Pointers must be declared before they can be used, just like a normal variable. The syntax of declaring a pointer is to place a * in front of the name. A pointer is associated with a type (such as int and double ) too.

What happens when a pointer is declared?

If you see the * in a declaration statement, with a type in front of the *, a pointer is being declared for the first time. AFTER that, when you see the * on the pointer name, you are dereferencing the pointer to get to the target.

Where should the asterisk go in a pointer?

When declaring a pointer type, place the asterisk next to the type name. Although you generally should not declare multiple variables on a single line, if you do, the asterisk has to be included with each variable.

Which is best way of declaring pointer variable?

First, declaring a pointer variable: char *ptr; This declaration tells us the pointer type (char), pointer level ( * ), and variable name ( ptr ).


1 Answers

Please have a look at the available options in menu [Tools] -> [Options] -> [Text Editor] -> [C/C++] -> [Formatting] -> [Spacing] -> [Pointer/Reference alignment].

like image 53
J. Doe Avatar answered Oct 26 '22 20:10

J. Doe