This Post Contains A C Program To Print An Array Using Pointer
With Correct Source Code, Algorithm & Output. This Program Is
Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will
Help You To Understand The Concept Of 'Arrays' & 'Pointers' From C
Language. It Is A Well-Structured Program With Proper Comments Which
Provides Step-By-Step Description Of Various Features Of The Language In
A Simple & Easy-To-Understand Way.
# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.
Where UB = largest index i.e. upper bound.# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.
- A linear array is a list of finite number 'n' of homogeneous data elements.
- The elements of array are referenced by index set consisting of 'n' consecutive numbers.
- The elements of array are stored respectively in successive memory locations.
- The number 'n' of elements is called as 'length' or 'size' of the array.
- Length Of Array = UB - LB + 1.
LB = smallest index i.e. lower bound.
- The elements of array A may be denoted by subscript notation.
- But in languages generally bracket notation is used.
C Program To Print An Array Using Pointer.
/* Declaration Of Header Files */
#include<stdio.h>
#include<conio.h>
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int i, a[10], *ptr;
clrscr();
/* Asking For The Input From User */
printf(" \n Please Enter 10 Numbers For An Array 'A' : ");
for(i=0; i<10; i++)
{
scanf("%d", &a[i]);
}
/* Printing The Output Onto The Screen/Console */
ptr=&a; // Or You Can Also Denote ptr=&a[0];
printf(" \n The Entered Numbers Are : \n ");
for(i=0; i<10; i++)
{
printf("%d \t", *ptr);
ptr++;
}
getch();
}
/* End Of Main Program */
Output :
Please Enter 10 Numbers For An Array 'A' :
1 2 3 4 5 6 7 8 9 10
The Entered Numbers Are :
1 2 3 4 5 6 7 8 9 10
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
C Program To Print An Array Onto Screen/Console.
/* Declaration Of Header Files */
#include<stdio.h>
#include<conio.h>
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int i, a[10];
clrscr();
/* Asking For The Input From User */
printf(" \n Please Enter 10 Numbers For An Array 'A' : ");
for(i=0; i<10; i++)
{
scanf("%d", &a[i]);
}
/* Printing The Output Onto The Screen/Console */
printf(" \n The Entered Numbers Are : \n ");
for(i=0; i<10; i++)
{
printf("%d \t", a[i]);
}
getch();
}
/* End Of Main Program */
Output :
Please Enter 10 Numbers For An Array 'A' :
1 2 3 4 5 6 7 8 9 10
The Entered Numbers Are :
1 2 3 4 5 6 7 8 9 10
/* Declaration Of Header Files */
#include<stdio.h>
#include<conio.h>
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int i, a[10], *ptr;
clrscr();
/* Asking For The Input From User */
printf(" \n Please Enter 10 Numbers For An Array 'A' : ");
for(i=0; i<10; i++)
{
scanf("%d", &a[i]);
}
/* Printing The Output Onto The Screen/Console */
ptr=&a; // Or You Can Also Denote ptr=&a[0];
printf(" \n The Entered Numbers Are : \n ");
for(i=0; i<10; i++)
{
printf("%d \t", *ptr);
ptr++;
}
getch();
}
/* End Of Main Program */
Output :
Please Enter 10 Numbers For An Array 'A' :
1 2 3 4 5 6 7 8 9 10
The Entered Numbers Are :
1 2 3 4 5 6 7 8 9 10
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
C Program To Print An Array Onto Screen/Console.
/* Declaration Of Header Files */
#include<stdio.h>
#include<conio.h>
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int i, a[10];
clrscr();
/* Asking For The Input From User */
printf(" \n Please Enter 10 Numbers For An Array 'A' : ");
for(i=0; i<10; i++)
{
scanf("%d", &a[i]);
}
/* Printing The Output Onto The Screen/Console */
printf(" \n The Entered Numbers Are : \n ");
for(i=0; i<10; i++)
{
printf("%d \t", a[i]);
}
getch();
}
/* End Of Main Program */
Output :
Please Enter 10 Numbers For An Array 'A' :
1 2 3 4 5 6 7 8 9 10
The Entered Numbers Are :
1 2 3 4 5 6 7 8 9 10
No comments:
Post a Comment