0

Pointer use?

What is the advantages in using pointer in coding in C++? I dont actually get it because we can actually call a variables by using the variables name.

13th Nov 2018, 6:15 PM
Abdul Malik
Abdul Malik - avatar
4 Answers
+ 3
"What is the advantages in using pointer in coding in C++?" Using pointers significantly improves performance for repetitive operations like traversing iterable data structures, e.g. strings, lookup tables, control tables and tree structures. In particular, it is often much cheaper in time and space to copy and dereference pointers than it is to copy and access the data to which the pointers point. [...] Âč. ____ Âč https://en.wikipedia.org/wiki/Pointer_(computer_programming)
13th Nov 2018, 6:24 PM
Babak
Babak - avatar
+ 3
Every one of them has its own place to use. For example, for passing large objects such as an array of 1000 integers to functions, the compiler passes it automatically by reference. You can pass your simple variables as reference, as well. But for smaller objects it's not worth doing that because it clutter the program. Also, in some situation it's much cleaner to use pointers like so void f(int *a, int *b) { *a++; *b++; } instead of typedef struct { int a, b; } type_t; type_t f(int a, int b) { type_t x; x.a = ++a; x.b = ++b; return x; } for having 2 return values.
1st Dec 2018, 10:20 AM
Babak
Babak - avatar
+ 1
ouh... thank you C++ Soldier (Babak)
1st Dec 2018, 11:38 AM
Abdul Malik
Abdul Malik - avatar
0
Ohh i see.. so we can just replace variables with pointer?? or its better using variables??
1st Dec 2018, 7:26 AM
Abdul Malik
Abdul Malik - avatar