Using Pointers With Array Input Output – Write a C program to input and output n elements in a one dimensional array.
Using Pointers With Array Input Output – C Program
#include <stdio.h> int main() { int a[50], i,n; int *ptr; printf("\n C Pointer Progrmming Examples:"); printf("\n Input and output numbers in One Dimensional Array:"); printf("\n Using Pointers in C"); printf("\n --------------------------------------------------\n"); printf(" Enter the number of elements of the array:"); scanf("%d",&n); ptr = a; printf(" Array Input:\n"); for(i=0;i<n;i++) { printf(" Enter Element a[%d] : ",i); scanf("%d",ptr++); } printf(" You enetered the following elements: \n"); ptr = a; for(i=0;i<n;i++) { printf(" Element a[%d] = %d \n",i,*ptr++); } return 0; }
Output
C Pointer Programming Examples:
Input and output numbers in One Dimensional Array:
Using Pointers in C
————————————————–
Enter the number of elements of the array:7
Array Input:
Enter Element a[0] : 11
Enter Element a[1] : 22
Enter Element a[2] : 345
Enter Element a[3] : 678
Enter Element a[4] : 876
Enter Element a[5] : 900
Enter Element a[6] : 1000
You entered the following elements:
Element a[0] = 11
Element a[1] = 22
Element a[2] = 345
Element a[3] = 678
Element a[4] = 876
Element a[5] = 900
Element a[6] = 1000
You may also like more on C Pointers:
- Understanding C Pointers
- Pointer Declaration With Example Program
- Using Pointers C ProgramĀ to Add Two Numbers