with Example C Program
Subject and UNIT: Programming in C: Unit III (b): Pointers
In this section, we will see how pointers can be used to access a three-dimensional array.
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
Elements of a two-dimensional array are stored in contiguous memory locations. A two-dimensional array is not the same as an array of pointers to one-dimensional arrays.
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
An array of pointers can be declared as int *ptr [10];The above statement declares an array of 10 pointers where each of the pointer points to an integer variable.
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
In C, strings are treated as arrays of characters that are terminated with a binary zero character (written as '\0').
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
When memory is allocated to an array, its base address is fixed and it cannot be changed during program execution. In other words, an array name is an address constant. Therefore, its value cannot be changed.
with Example C Programs | Pointers
Subject and UNIT: Programming in C: Unit III (b): Pointers
An array can be passed to a function using pointers. For this, a function that expects an array can declare the formal parameter in either of the two following ways: func (int arr[]); OR func (int *arr);
Syntax with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
The concept of array is very much bound to the one of the pointers. An array occupies consecutive memory locations.
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
We have already seen call-by-value method of passing parametres to a function. Using call-by-value method, it is impossible to modify the actual parameters when you pass them to a function.
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
A generic pointer is a pointer variable that has void as its data type. The void pointer, or the generic pointer, is a special type of pointer that can be used to point to variables of any data type. It is declared like a normal pointer variable but using the void keyword as the pointer's data type.
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
We have seen that a pointer variable is a pointer to some other variable of the same data type. However, in some cases we may prefer to have null pointer which is a special pointer that does not point to any value.
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
Like other variables, pointer variables can also be used in expressions. For example, if ptr1 and ptr2 are pointers, then the following statements are valid.
with Example C Programs
Subject and UNIT: Programming in C: Unit III (b): Pointers
A pointer provides access to a variable by using the address of that variable. A pointer variable is therefore a variable that stores the address of another variable.