0
Poi ter
what is the difference between these two codes int p=88; int *a=&p; and -------------- int *a= new int; int *a=88; what is the difference between these to pointers. thanks
2 Respuestas
+ 3
1.) p is an int on the stack. a is a pointer that points to p, or in other words it is a variable that stores the address of a.
2.) now a is a pointer that points to an int which is stored on the heap. then you just store 88 in the variable a points to.
maybe you search for differences between heap and stack for more information on this or ask here in another question.
+ 2
if in the second example you actually wanted to declare a new int pointer and directing initializing it with 88, so int *a = 88;
means that this pointer stores the address 88.
its the same as saying int *a; a = 88;
so when you then acessing *a,.you are talimg sizeof(int), (which is usually 4)bytes at address 88 nd interpreting it as an int
usuly it does not make semse to give explicit values for addresses