Popular Tutorials
Start Learning CCertification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
C Program to Access Array Elements Using Pointer
In this example, you will learn to access elements of an array using a pointer.
To understand this example, you should have the knowledge of the following C programming topics:
Access Array Elements Using Pointers
#include <stdio.h>
int main() {
int data[5];
printf("Enter elements: ");
for (int i = 0; i < 5; ++i)
scanf("%d", data + i);
printf("You entered: \n");
for (int i = 0; i < 5; ++i)
printf("%d\n", *(data + i));
return 0;
}
Output
Enter elements: 1 2 3 5 4 You entered: 1 2 3 5 4
In this program, the elements are stored in the integer array data[].
Then, the elements of the array are accessed using the pointer notation. By the way,
data[0]is equivalent to*dataand&data[0]is equivalent todatadata[1]is equivalent to*(data + 1)and&data[1]is equivalent todata + 1data[2]is equivalent to*(data + 2)and&data[2]is equivalent todata + 2...data[i]is equivalent to*(data + i)and&data[i]is equivalent todata + i
Visit this page to learn about the relationship between pointers and arrays.
Did you find this article helpful?