Passing array as an argument 📥

 

Passing Array As An Argument


/*Remember, array is always passed by address to a function. Thus, any change made by the function (to anairay) i s shown in the original array as well.*/



#include<stdio.h>

void sqArr(int[]); // function to square the contents of an array

void main()

{

int arr[5]=(1,2,3,4,5); 

int i;

printf("Array before function call: ");

for(i=0;i<5;i++)

{

printf("%d", arr[i]);

}

sqArr(arr);

printf("\nArray after function call: ");

for(i=0;i<5;i++)

{

printf("%d", arr[i]);

}

}

void sqArr(int a[])

{

int i;

for(i=0;i<5;i++)

}

}


OUTPUT:

Array before function call: 12345 

Array after function call: 149 16 25





Comments

Popular posts from this blog

Basic Computer 🖥️💻 Organisation

Introduction of computer 🖥️🖥️🖱️