+ 1
what is the difference between *ptr and int * ptr
pointers
4 odpowiedzi
+ 11
When you do:
int* ptr;
You are declaring a pointer of type integer named ptr.
When you do:
*ptr;
You tell the program to point to the address stored in ptr.
E.g.
int x = 5;
int *ptr = &x; // ptr stores address of x.
cout << *ptr; // point to the address of x, and print the value.
+ 7
@Fabian has also made legit points.
+ 2
there is no difference between int* ptr and int *ptr. but consider you try to create two pointers in a line:
int *x, *y; // creates two int pointers
int* x, y; //creates an int pointer x but y is "just" an int.
Therefore int *x usually results in less errors.
Edit: reading the other reply I might have misunderstood your question.
0
thanks everyone for explaining it so clearly