I don't understand why we use " & " in the code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I don't understand why we use " & " in the code

28th Jul 2016, 1:22 PM
Raphael Korosso
Raphael Korosso - avatar
7 Answers
+ 3
"&" stores the memory address int cont = 14; int *d; d = &cont; int d* declares the pointer d d = &cont; stores the memory address of cont in *d cout << *d << endl; prints 14
28th Jul 2016, 1:47 PM
Jaque
Jaque - avatar
+ 1
& - refer to the address of the pointer. int *p=5 cout<<&p; this &p will be refers to the memory address of the pointer where the value is stored.
28th Jul 2016, 5:21 PM
saurabh mandy
saurabh mandy - avatar
+ 1
Every variable have an address, & is used to get the address of that variable int x x is variable to get the address of x, we use & like &x
29th Jul 2016, 3:59 PM
Govind Singhal
Govind Singhal - avatar
0
Thats call buly reference
28th Jul 2016, 2:13 PM
Utkarsh
0
thank you, greatly appreciated
28th Jul 2016, 2:24 PM
Raphael Korosso
Raphael Korosso - avatar
0
& is used to refer to an address of a pointer as said by others. But also it is used in call by reference in functions as in, func(int&x){} here your argument say a is defined as int and den assigned as a=x. so if value of x changes then that of a changes as well .
28th Jul 2016, 5:32 PM
Pranav T
Pranav T - avatar
0
Or maybe you are talking about bitwise-and(&)?
28th Jul 2016, 5:38 PM
ddrodoric