The concept of pointers

I am new to C, and as I read, I understand the concept of pointers. Thus, after links from several books and sites, I still cannot understand how the pointer is used to save memory.

The pointer indicates the location of the address of another variable, for example: int * ptr = & var;

From the above, for example, ptr contains the address var, which itself is stored in another memory location. So my question is:

1) why do we use pointers when the pointer value is stored in a separate memory cell, thereby increasing memory usage?

2) Why don't we use the variable name (var in this case) instead of using a different memory space for pointers

+3
source share
4

, , . , , , .

, , - , . , , , .

. .

. , , .

, / , , . , .

C , . , , .

, , Java, . Java . , , , Java .

C , . - , C , , .

+1

. , , , (, struct) , . 4 , - fiur. . , , , .   , .

, , , , . . , .

+2

C , , . , , . , . , .

Java .

+1

, . : C. ,

Arr[1] = 3;

:

*(Arr+1) = 3;

char *str = "I am a sequence of characters"

, , , .

, . , , :

  • 1.

, ? .

, , .

The compiler is your friend to optimize the material, but even a friend can use some help, and you can provide this with pointers. Pointers allow you to tailor your program, as other limited constructs will never allow you.

0
source

All Articles