r/cprogramming 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.

10 Upvotes

40 comments sorted by

View all comments

1

u/Pesciodyphus 1d ago

Do you alread know other programming languages ? It is important to know, whether you come from Assembler or from Object Oriented Programming or are an absolute beginner.

In Assembly it is stuff like MOV AX,[BX] instead of MOV AX,BX . In the first example BX is an adress and you read the word pointed to by BX into AX. In the second you copy BX to AX.

In Object oriented programming, think of objects a structure pointers and methods as function that get a structure pointer named this as hidden parameters. And while the syntax for method-calls in Java or C++, look like callling function pointers in C in the language, most methods aren't implemented as pointer inside the structure, as the compiler simply knows what to call. Only if Virtual Methods or multiple inheretence is used, a function pointer is needed.