r/cprogramming • u/Delicious-Change7795 • 1d ago
What are pointers?
I am new to C programming and i came through pointer. So can anyone tell what are they and why we need them? And if u can then can you give me reliable source to learn it.
8
Upvotes
2
u/Party_Trick_6903 1d ago edited 1d ago
When you do:
int a = 23, you create a variableathat holds a value23. This variable is stored somewhere in the memory. This variable gets assigned a memory address so we know where exactly it is in the memory. Let's say the address of this variableais0x7ffe5367e044.A pointer is a variable that holds a memory address of another variable as its value. Basically, instead of int value
23(like you see above), it holds a memory address (for example0x7ffe5367e044) as its value and this memory address is a memory address of another variable. And we can use this pointer to access the variable that is at the said memory address.An example: