Escolar Documentos
Profissional Documentos
Cultura Documentos
sNo=49&qId=59dca4c20cf2e6552052c3ae&bd=AY3RFZHVEQg%3D%3D&lid=5c2…
S.No: 49 Exp. Name: Write a C program to access elements of an Array using Pointers Date:
Aim:
Page No:
Write a program to read and display the elements of an array using pointers.
At the time of execution, the program should print the message on the console as:
ID: 18331a0431
Enter n value :
Enter n value : 4
Next, the program should print the message on the console as:
Enter 4 values :
Enter 4 values : 11 55 44 33
AccessArrayUsingPointers.c
#include <stdio.h>
#include <stdlib.h>
#include "AccessArray.c"
void main() {
int *p, n, i;
printf("Enter n value : ");
scanf("%d", &n);
p = (int *) malloc(n * sizeof(int));
printf("Enter %d values : ", n);
read(p, n);
printf("The given array elements are : ");
display(p, n);
printf("\n");
}
MVGR College of Engineering (Autonomous)
AccessArray.c
https://mvgrce.codetantra.com/secure/labs-q.jsp?sNo=49&qId=59dca4c20cf2e6552052c3ae&bd=AY3RFZHVEQg%3D%3D&lid=5c2344c364bac… 1/2
9/23/2019 https://mvgrce.codetantra.com/secure/labs-q.jsp?sNo=49&qId=59dca4c20cf2e6552052c3ae&bd=AY3RFZHVEQg%3D%3D&lid=5c2…
{
int i;
for(i=0;i<n;i++)
{
Page No:
printf("%d ",*(p+i));
}
}
ID: 18331a0431
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
Enter n value : 5
Enter 5 values : 2 5 7 4 1
The given array elements are : 2 5 7 4 1
https://mvgrce.codetantra.com/secure/labs-q.jsp?sNo=49&qId=59dca4c20cf2e6552052c3ae&bd=AY3RFZHVEQg%3D%3D&lid=5c2344c364bac… 2/2