
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to pass entire array as an argument to a function in C language?
Array
The array is a group of related items that store with a common name. Following are the two ways of passing arrays as arguments to functions −
- sending entire array as argument to function
- sending individual elements as argument to function
Sending entire array as an argument to a function
To send entire array as argument, just send the array name in the function call.
To receive an array, it must be declared in the function header.
Example 1
#include<stdio.h> main (){ void display (int a[5]); int a[5], i; clrscr(); printf ("enter 5 elements"); for (i=0; i<5; i++) scanf("%d", &a[i]); display (a); //calling array getch( ); } void display (int a[5]){ int i; printf ("elements of the array are"); for (i=0; i<5; i++) printf("%d ", a[i]); }
Output
Enter 5 elements 10 20 30 40 50 Elements of the array are 10 20 30 40 50
Example 2
Let us consider another example to know more about passing entire array as argument to function −
#include<stdio.h> main (){ void number(int a[5]); int a[5], i; printf ("enter 5 elements\n"); for (i=0; i<5; i++) scanf("%d", &a[i]); number(a); //calling array getch( ); } void number(int a[5]){ int i; printf ("elements of the array are\n"); for (i=0; i<5; i++) printf("%d\n" , a[i]); }
Output
enter 5 elements 100 200 300 400 500 elements of the array are 100 200 300 400 500
- Related Questions & Answers
- How to pass entire structure as an argument to function in C language?
- How to pass an entire structure as an argument to function in C?
- How to send an entire array as an argument in C language?
- How to pass individual elements in an array as argument to function in C language?
- How to pass the address of structure as an argument to function in C language?
- How to pass Python function as a function argument?
- How to pass a dictionary as argument in Python function?
- How to pass the address of structure as an argument to function in C?
- Java Program to Pass ArrayList as the function argument
- How to send individual elements as an argument in C language?
- How to pass individual members of structure as arguments to function in C language?
- Can we pass objects as an argument in Java?
- How to pass argument to an Exception in Python?
- How to pass an object as a parameter in JavaScript function?
- Java Program to pass lambda expression as a method argument
Advertisements