C सरणी पैरामीटर को पॉइंटर्स के रूप में मानता है क्योंकि यह कम समय लेने वाला और अधिक कुशल है। यद्यपि यदि हम किसी फ़ंक्शन के लिए सरणी के प्रत्येक तत्व के पते को तर्क के रूप में पास कर सकते हैं, लेकिन यह अधिक समय लेने वाला होगा। इसलिए पहले तत्व के आधार पते को फ़ंक्शन में पास करना बेहतर है जैसे:
void fun(int a[]) {
…
}
void fun(int *a) { //more efficient.
…..
} यहां C में एक नमूना कोड दिया गया है:
#include
void display1(int a[]) //printing the array content
{
int i;
printf("\nCurrent content of the array is: \n");
for(i = 0; i < 5; i++)
printf(" %d",a[i]);
}
void display2(int *a) //printing the array content
{
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}; //initialization of array elements
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