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.
4 Respostas
+ 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)
+ 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.
+ 1
ouh... thank you C++ Soldier (Babak)
0
Ohh i see.. so we can just replace variables with pointer??
or its better using variables??