+ 2

pointer

can I ask, how pointers are used in an actual application? can anyone give an example? thanks in advance.,, :)

21st Jun 2017, 11:51 AM
Herlem A. Martinez
Herlem A. Martinez - avatar
3 ответов
+ 8
pointer is a variable which stores the address of another variable in pointer we uses * and &. *refers the value of that address and & refers the address of the variable .for ex int main(){ int *p; int a=10; p=&a; cout<<" the address of a "<<(unsigned)&a; cout<<"the value of a "<<*p; } output:first shows the address of the a and second shows the value of a.
21st Jun 2017, 12:52 PM
venkata ramarao yarlagadda
venkata ramarao yarlagadda - avatar
+ 7
An example of what pointers can be used for in practical application: http://www.cprogramming.com/tutorial/lesson18.html
21st Jun 2017, 1:57 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Hello friend, I will gave you an example: Imagina that you have a program that work with numbers very high numbers void mathfunction (long long* number){ //this is a pointer to this high number,imagina that this function make some xD } int main(){ long long number; //imagina that we declared a high number mathfunction(&number); //the pointers make that for the function dont copy the number(this will save memory) and with the pointer the function will be to the memory direction and read the number without copy it for the parameter. } the pointers can help we to save memory and with dinamic lists
21st Jun 2017, 12:27 PM
David Vazkez Perez
David Vazkez Perez - avatar