- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 individual elements in an array as argument to function in C language?
If individual elements are to be passed as arguments, then array elements along with their subscripts must be given in function call.
To receive the elements, simple variables are used in function definition.
Example 1
#include<stdio.h> main (){ void display (int, int); int a[5], i; clrscr(); printf (“enter 5 elements”); for (i=0; i<5; i++) scanf("%d", &a[i]); display (a [0], a[4]); //calling function with individual arguments getch( ); } void display (int a, int b){ //called function with individual arguments print f ("first element = %d",a); printf ("last element = %d",b); }
Output
Enter 5 elements 10 20 30 40 50 First element = 10 Last element = 50
Example 2
Consider another example for passing individual elements as argument to a function.
#include<stdio.h> main (){ void arguments(int,int); int a[10], i; printf ("enter 6 elements:
"); for (i=0; i<6; i++) scanf("%d", &a[i]); arguments(a[0],a[5]); //calling function with individual arguments getch( ); } void arguments(int a, int b){ //called function with individual arguments printf ("first element = %d
",a); printf ("last element = %d
",b); }
Output
enter 6 elements: 1 2 3 4 5 6 first element = 1 last element = 6
- Related Articles
- How to send individual elements as an argument in C language?
- How to pass entire array as an argument to a function in C language?
- How to pass entire structure as an argument to function in C language?
- How to pass the address of structure as an argument to function in C language?
- How to pass individual members of structure as arguments 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 the address of structure as an argument to function in C?
- How to pass the individual members as arguments to function using structure elements?
- How to pass Python function as a function argument?
- How to pass a dictionary as argument in Python function?
- Java Program to Pass ArrayList as the function argument
- How to pass argument to an Exception in Python?
- Can we pass objects as an argument in Java?
- How to pass an argument to the event handler in Tkinter?

Advertisements