Skip to content
Justice Tech School

Pointer Arithmetic and Arrays

An array name acts like a pointer to its first element. Adding 1 to a pointer moves to the next element of that type. So arr[i] is the same as *(arr + i).

Example
int nums[3] = {10, 20, 30};
int *p = nums;
printf("%d\n", *p);
printf("%d\n", *(p + 1));
printf("%d\n", nums[2] == *(nums + 2));
p++;
printf("%d\n", *p);

Result

10
20
1
20

Exercise

Move to the next element.

p;

Quiz Test

What is *(arr + 2) the same as?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.