+ 2

What's the use of & in program why do we need to know about their memory address?

25th Dec 2017, 7:49 AM
Mohit M Gulecha
Mohit M Gulecha - avatar
2 Answers
+ 1
In C and C++ the & notation is used to pass the address of variables to methods and functions, or to point to the location of data allocated in heap memory. Without pointers, data are fully allocated in the stack and duplicated (cloned) each when passed as parameter reassigned to another variable. which is inefficient.
25th Dec 2017, 8:05 AM
ifl
ifl - avatar
+ 1
the & notation is used in C and C++ for pointers to make the use explicit. whereas in languages like java an python the use of pointers is hidden . e.g. objects in java are effectively address of data in the heap, only primitive variables are allocated fully in the stack.
25th Dec 2017, 8:09 AM
ifl
ifl - avatar