0

What is the differences between * and &

18th Aug 2017, 2:56 PM
ANWAR TAHA MOHAMMED AL-HITAR
ANWAR TAHA MOHAMMED AL-HITAR - avatar
3 odpowiedzi
+ 6
int n = 5;// an integer variable called n int *ptr = &n;// a pointer variable of type integer initialized by address of n * designate a pointer variable in this case and & indicate the address of something(&n is the address of n)
18th Aug 2017, 3:55 PM
Babak
Babak - avatar
+ 3
the difference between * and & in pointers is * sgin is used for declaring pointer in c++ program ex. int * ptr so int is variable datatype and * sgin must be used in declearing point because it identifies it is a pointer and ptr is it's name and & operator is used for retrieving address of any variable e.x int main() { int a; int *a; a=10; ptr=&a; cout<<a<<endl; cout<<ptr<<endl; } so the output is 10 3fx10. // it should be different in other computer because it is according to ram prodcedure the ram automatic assgin address to any thing in ram . you can also used. & operator without declerating pointer such as cout<<&a;
18th Aug 2017, 3:54 PM
SatanicAngal666
SatanicAngal666 - avatar
+ 1
& returns the memory address of its operand. It is applicable to objects in memory i.e variables and array elements. when * is applied to a pointer, the pointer can access the object it points to %p format specifier causes printf() to display the address in the format used by the host computer. #include<stdio.h> int main() { int a=5; int *ptr=&a; printf("%p\n",ptr); printf("%p\n",&a); printf("%p\n",*ptr); *ptr=*ptr+1; printf("%d",a); return 0; } I got output like 0060FF08 0060FF08 5 6
18th Aug 2017, 5:27 PM
Rishi Anand
Rishi Anand - avatar