Passing 1-D array to Function in C using Pointer notation - C Programming Tutorial 111

Published: 26 June 2020
on channel: ChidresTechTutorials
1,146
14

Passing 1-D array to Function in C using Pointer notation - C Programming Tutorial 111
An array name represents address of the first element in the array. So, whenever we pass an array to a function, address of the first element in the array is passed.
While calling a function; if we pass address of a memory location; then it is called as pass by reference or call by reference.

There are 2 different notations for passing an array to a function:

1. Array notation : [ ]
basic syntax of declaring a function; for accepting 1D array using array notation.
return_type functionName(datatype paramName[ ]);
Example:
void display(int arr[ ],int arraySize);

2. Pointer notation : *
basic syntax of declaring a function; for accepting 1D array using pointer notation.
return_type functionName(datatype *paramName);
Example:
void display(int *arr,int arraySize);

Note:
While passing an array to a function; it is also recommended to pass its size.


Example Code: Passing 1D array to a function using pointer notation.
#include <stdio.h>
void display(int *arr,int size);
int main()
{
int arr1[5] = {1,2,3,4,5};
display(arr1,5);
return 0;
}
void display(int *arr,int size)
{
int i=0;
for(i=0; i<size; i++)
{
printf("%d\n",*(arr+i));
}
}

Note:
replace < with less-than symbol.
replace > with greater-than symbol.

=========================================

Follow the link for next video:
   • Passing 2-D array to Function in C us...  

Follow the link for previous video:
   • Passing 1-D Array to Function in C us...  

=========================================

C Programming Tutorials Playlist:
   • C Programming Tutorials  

=========================================
Watch My Other Useful Tutorials:-

Computer Programming Fundamentals Playlist:-
   • Computer Programming Fundamentals  

C Practical LAB Exercises Playlist:-
   • C Practical Programs  

C++ Tutorials Playlist:
   • C++ Tutorials  

=========================================

► Subscribe to our YouTube channel:
   / chidrestechtutorials  

► Visit our Website:
https://www.chidrestechtutorials.com

=========================================
Hash Tags:-
#ChidresTechTutorials #CProgramming #CProgrammingTutorial


On this page of the site you can watch the video online Passing 1-D array to Function in C using Pointer notation - C Programming Tutorial 111 with a duration of hours minute second in good quality, which was uploaded by the user ChidresTechTutorials 26 June 2020, share the link with friends and acquaintances, this video has already been watched 1,146 times on youtube and it was liked by 14 viewers. Enjoy your viewing!