Fundamentals of pointers and Declaration, initialization and dereferencing of pointers in c programming
#Fundamentals of pointers Declaration, initialization and dereferencing of pointers in c programming
The point of pointers is efficiency. It is easier to give someone the address of your location than it is to carry your location with you
we observe pointer is a variable that stores the memory address of another variable as its value.
A pointer variable points to a data type (like array, char, int) of the same type, and is created with the * operator.
A variable that has a memory address is called a pointer. The addresses of other variables or memory components are stored in pointers. For a different kind of parameter passing known as Pass By Address, pointers are particularly helpful. Pointers are necessary for the dynamic allocation of memory.
Declaration and Initialization a variable :
int *ptr; // Pointer to an integer
int x = 10;
int *ptr = &x;
accessing the value it points to:
int y = *ptr;
Declaration and Initialization and accessing array:
int arr[3] = {1, 2, 3};
Using c pointer fundamentals is crucial for efficient memory management and manipulation in C.
It is important to use pointers carefully prevent invalid memory locations or causing memory.Computer Science Fundamentals is part of Pointers.
Both operators are supported in two forms: postfix ( p++ and p-- ) and prefix ( ++p and --p ). The result of p++ and p-- is the value of p before the operation. The result of ++p and --p is the value of p after the operation.
int *p = arr; // 'p' points to the first element of 'arr'