Home / Programs / Write a program where the calling function must simply pass an appropriate array pointer and maximum number of elements as arguments. These functions may also be written explicitly in terms of indirect access.
🚀 Programming Example

Write a program where the calling function must simply pass an appropriate array pointer and maximum number of elements as arguments. These functions may also be written explicitly in terms of indirect access.

👁 783 Views
💻 Practical Program
📘 Step Learning
Write a program where the calling function must simply pass an appropriate array pointer and maximum number of elements as arguments. These functions may also be written explicitly in terms of indirec

💻 Program Code

#include <stdio.h>
#define MAX 50
int main()
{
	int arr[MAX],n;
	int getdata(int *, int);
	void show(int *, int);
	n = getdata(arr, MAX);
	show(arr, n);
	return 0;
}
/* Function reads scores in an array. */
int getdata(int *a, int n)
{
	int x, i = 0;
	printf("\n Enter the array size\n");
	scanf("%d",&n);
    printf("\n Enter the array elements one by one\n");
	while(i < n)
	{
		scanf("%d", &x);
		*(a + i) = x;
		i++;
	}
	return i;
}
void show(int *a, int n)
{
	int i;
	for(i=0;i<n;++i)
	printf("\n %d", *(a+i));
}


                        

🖥 Program Output


 Enter the array size
5

 Enter the array elements one by one
10
11
12
13
14

 10
 11
 12
 13
 14  
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.