Right Click to Search

Sunday, August 1, 2024

Passing Entire 1-D Array to Function in C Programming


Passing Entire 1-D Array to Function in C Programming
  • Array is passed to function Completely.
  • Parameter Passing Method : Pass by Reference
  • It is Also Called "Pass by Address"
  • Original Copy is Passed to Function
  • Function Body Can Modify Original Value.
  • Example :
#include<stdio.h>
#include<conio.h>
void modify(int b[3]);
void main()
{
int arr[3] = {1,2,3};
modify(arr);
for(i=0;i<3;i++)
  printf("%d",arr[i]);
getch();
}
void modify(int a[3])
{
int i;
for(i=0;i<3;i++)
  a[i] = a[i]*a[i];
}
Output : 
1 4 9
  •  Here "arr" is same as "a" because Base Address of Array "arr" is stored in Array "a"
Alternate Way of Writing Function Header :
void modify(int a[3])
OR
void modify(int *a)

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates