C Program to Access Array Elements Using Pointer
ADVERTISEMENTS
C program to Access Array Elements Using a Pointer.
In this article, you will learn how to access the element of the array using the C pointer.
Example
Enter the size of Array: 3
Enter the elements of the Array:
2
3
4
You entered these elements:
2
3
4
You should have knowledge of the following topics in c programming to understand this program:
- C For Loop
- C Arrays
- C Pointers
Source
// C Program to Access Array Elements Using Pointer
#include <stdio.h>
// It's the main function of the program
int main() {
int count;
printf("Enter the size of Array: ");
scanf("%d", &count);
int arr[count];
printf("\nEnter the elements of the Array:\n");
for (int i = 0; i < count; i++) {
scanf("%d", &arr[i]);
}
printf("\nYou entered these elements:\n");
for (int i = 0; i < count; i++) {
printf("%d\n", *(arr + i));
}
return 0;
}
Output
Enter the size of Array: 5
Enter the elements of the Array:
1
2
3
4
5
You entered these elements:
1
2
3
4
5