forked from goldendeepkaur/PPS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP35.c
More file actions
29 lines (27 loc) · 706 Bytes
/
P35.c
File metadata and controls
29 lines (27 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//PROGRAM TO ACCESS ARRAY ELEMENTS USING POINTERS
#include <stdio.h>
void main()
{
int arr[10];
int N, i;
int * ptr = arr; // Pointer to arr[0]
printf("Enter number of elements in the array (<=10): ");
scanf("%d", &N);
printf("Enter elements in array:\n");
for (i = 0; i < N; i++)
{
scanf("%d", ptr);
// Move pointer to next array element
ptr++;
}
// pointer again points back to first array element
ptr = arr;
printf("Array elements: ");
for (i = 0; i < N; i++)
{
// Print value pointed by the pointer
printf("%d, ", *ptr);
// Move pointer to next array element
ptr++;
}
}