Initialization of Pointer Arrays in C
Initialization of Pointer Arrays in C
Initialization of
C - Anonymous Structure
and Union Pointer Arrays in C
C - Unions A pointer in C is a variable that
stores the address of another
C - Bit Fields variable. The name of the pointer
variable must be prefixed by the "*"
symbol. Just as in the case of a
C - Typedef
normal variable, we can also declare
an "array of pointers", where each
C - Input & Output
subscript of the array holds the
address of an array type.
C - File I/O
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 1/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
#include <stdio.h>
int main(){
return 0;
}
Output
ptr[0]= 0
ptr[1]= 0
ptr[2]= 0
ptr[3]= 0
ptr[4]= 0
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 2/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
#include <stdio.h>
int main(){
return 0;
}
Output
Example 3
#include <stdio.h>
int main(){
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 3/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
return 0;
}
Output
Example 1
#include <stdio.h>
int main(){
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 4/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
return 0;
}
Output
Example 2: Traversing a 2D
Array using a Pointer Array
#include <stdio.h>
int main(){
// 2d array
int arr[3][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
};
// pointer
int (*ptr)[4] = arr;
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 5/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
return 0;
}
Output
1234
5678
Example 3
#include <stdio.h>
int main(){
// 2d array
int arr[3][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
};
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 6/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
// pointer
int *ptr = arr;
return 0;
}
Output
1 2 3 4
5 6 7 8
Array of Strings
In C programming, a string is an
array of char data type. Since the
name of an array also represents the
address of its 0th element, a string
can be declared as −
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 7/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
Example
#include <stdio.h>
int main(){
return 0;
}
Output
PYTHON
JAVASCRIPT
PHP
NODE JS
HTML
KOTLIN
C++
REACT JS
RUST
VBSCRIPT
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 8/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
Example
#include <stdio.h>
int main(){
return 0;
}
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 9/10
6/16/24, 1:16 PM Initialization of Pointer Arrays in C
Output
00
11
22
33
44
https://www.tutorialspoint.com/cprogramming/c_initialization_of_pointer_arrays.htm 10/10