C भाषा में एरे पैरामीटर को पॉइंटर के रूप में माना जाता है क्योंकि यह कम समय लेने वाला और अधिक कुशल होता है। हालांकि हम एरे के प्रत्येक तत्व का पता फंक्शन को आर्गुमेंट के रूप में पास कर सकते हैं, लेकिन यह अधिक समय लेगा। इसलिए पहले तत्व का बेस एड्रेस फंक्शन को पास करना बेहतर होता है, जैसे:
void fun(int a[]) { ... }
void fun(int *a) { // अधिक कुशल ... }
C में एक नमूना कोड:
#include <stdio.h>
void display1(int a[]) // एरे की सामग्री प्रिंट करना
{
int i;
printf("\nCurrent content of the array is: \n");
for(i = 0; i < 5; i++)
printf(" %d", a[i]);
}
void display2(int *a) // एरे की सामग्री प्रिंट करना
{
int i;
printf("\nCurrent content of the array is: \n");
for(i = 0; i < 5; i++)
printf(" %d", *(a+i));
}
int main()
{
int a[5] = {4, 2, 7, 9, 6}; // एरे तत्वों का आरंभीकरण
display1(a);
display2(a);
return 0;
}
आउटपुट:
Current content of the array is: 4 2 7 9 6 Current content of the array is: 4 2 7 9 6