+ 10

What is the difference between these two arguments?!

(int *p = &a;) vs (int a; int *p ; p = &a)

31st Mar 2018, 11:30 PM
Mohammad Hosein
Mohammad Hosein - avatar
3 Answers
+ 8
I don't see any difference. I tried both and they both work. The variable values printed out the same, but the pointers gave different addresses, as expected, since I made two sets of pointers. https://code.sololearn.com/c3XRLIH5UKQ5/?ref=app
1st Apr 2018, 12:11 AM
Eric Zatarack
Eric Zatarack - avatar
+ 3
int *p; //declares a variable p = &a; // initializes a variable int *p = &a; // does both in one line In both cases int a has to be already declared.
1st Apr 2018, 8:41 AM
Chris
Chris - avatar
+ 2
both are same they are just different methods of writing the same stuff in both examples *p is the pointer, &a is the address of a. address of a is assigned to pointer p
1st Apr 2018, 2:37 AM
‎ ‏‏‎Anonymous Guy