Pointer variables have many uses. Primarily, we use pointers to keep track of variables allocated on the heap (the free store). We cannot name these variables because they do not exist at compile time, so we must use pointer variables to store the addresses of these variables as and when they are allocated at runtime. Hence the return value of the C standard library malloc() function is a memory address.
We also need to use pointers when passing arrays to and from functions because arrays cannot be passed by value, they can only be passed by reference. More generally, we can use pointers to pass and return any variable by reference, particularly large structures that would be too expensive to copy if passed by value.
In C++ we can use native reference types rather than pointers, but in C there is no native reference type, so we must use pointers if we wish to work with memory addresses. We often use the term reference when referring to pointers in C, however there are important distinctions. Unlike a pointer, a reference is not a variable (it is an alias or alternate name for a memory address) and references can never be null. The null address (usually address 0) is a system address which we can assign to a pointer whenever we have no valid address to assign to it. Thus we can also use pointers as function arguments when "no object" may be a valid argument.
Pointers and arrays are closely related in C. In some respects, an array name behaves like a reference in C++. That is, the name refers to the start address of the array (the address of the first element of the array). As such, the name and the address of the name are one and the same, as is the address of the first element:
int a[100];
assert (a == &a);
assert (a == &a[0]);
The array subscript operator [] is nothing more than a sugar-coated abstraction to simplify the pointer arithmetic required to navigate an array. For any array a and any integer j within the range of a, we have the following equivalences:
a[j] j[a]
It often surprises people that a[j] and j[a] are equivalent, however the compiler will interpret j[a] as meaning *(j+a), which is nothing more than trivial pointer arithmetic. Such low-level cleverness does not belong in production code, of course.
What is the major advantage of using C-V-P graphs?
brown
Example: void foo( MyClass& object ){} // function with call by reference signature MyClass* p = new MyClass(); // instantiate a pointer to MyClass foo( *p ); // call by reference using the pointer
Storing data, mainly.
Your question makes no sense.
(*p)[23]
What is the major advantage of using C-V-P graphs?
It is a pointer that points to a member of a structure.
Increment or decrement the pointer by the required offset.
i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?
no
the purpose of pointer in c for saving the memory space.,and reduce the length and complexity of the program