Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer on type instead of variable name? [duplicate]

Tags:

c

pointers

Possible Duplicate:
In C, what is the correct syntax for declaring pointers?
Correct C pointer notation

What is the difference between

int* x

and

int *x

(if one exists) ?

like image 392
Stumbler Avatar asked Nov 29 '12 18:11

Stumbler


People also ask

Can pointers have the same name?

If they were each local to different functions (or different files) then they are in different 'scopes' then, YES then can have the same name.

How to print out pointer in C?

Printing pointers. You can print a pointer value using printf with the %p format specifier. To do so, you should convert the pointer to type void * first using a cast (see below for void * pointers), although on machines that don't have different representations for different pointer types, this may not be necessary.

How to declare and initialize pointer in c++?

You need to initialize a pointer by assigning it a valid address. This is normally done via the address-of operator ( & ). The address-of operator ( & ) operates on a variable, and returns the address of the variable. For example, if number is an int variable, &number returns the address of the variable number .

Can a pointer variable be changed?

The answer is "no", you cannot change the address of a variable.


2 Answers

They both the same. Only difference is that you cant declare many variables in such way:

int* x, a, b; //a and b are not pointers

int *x, *a, *b; //all are pointers

I use first notation, for me it shows that variable has pointer type, not pointer itself.

like image 98
Denis Ermolin Avatar answered Sep 30 '22 01:09

Denis Ermolin


It's the same definition of pointer. both are pointer to an int

like image 33
MOHAMED Avatar answered Sep 30 '22 02:09

MOHAMED