is it making a new copy of memory adress (or variable) when passing a pointer on function? if yes , so it is wasting more memory than a passing normal variable?
so whats the point of pointers?
if no, can you explain it to me?
is it making a new copy of memory adress (or variable) when passing a pointer on function?
A pointer is simply a type of variable that contains a memory address.
When you pass a pointer to a function, the value of the pointer is pushed onto the stack. Is this 'wasting memory"? That depends on whether the pointer was needed or not. If the pointer was needed, then it was not "wasted". A pointer takes however many bytes the address size is on your platform (4 bytes on a 32 bit platform). This is typically the same size as an int. If you're passing around large objects, it is more efficient to pass a pointer than to pass the object by value which requires copying the object.
Pointers are used arguments to many C functions. Pointers are less important in C++ where objects can be passed by reference. An exception to this with C++ is dynamic memory. Dynamic memory is always allocated and released via pointers.
When you pass an object by reference in C++, the compiler is actually generating a pointer to the object.