- 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 arrays are passed to functions in C/C++
In this tutorial, we will be discussing a program to understand how arrays are passed to functions.
In the case of C/C++, the arrays are passed to a function in the form of a pointer which provides the address to the very first element of the array.
Example
#include <stdio.h> //passing array as a pointer void fun(int arr[]){ unsigned int n = sizeof(arr)/sizeof(arr[0]); printf("\nArray size inside fun() is %d", n); } int main(){ int arr[] = {1, 2, 3, 4, 5, 6, 7, 8}; unsigned int n = sizeof(arr)/sizeof(arr[0]); printf("Array size inside main() is %d", n); fun(arr); return 0; }
Output
Array size inside main() is 8 Array size inside fun() is 2
- Related Articles
- How are parameters passed in C#?
- How are values assigned to arrays in C#?
- How are virtual functions implemented in C++?
- How command line arguments are passed in main method in C#?
- How do JavaScript primitive/object types passed in functions?
- Why doesn't C++ support functions returning arrays
- What are virtual functions in C#?
- Are arrays zero indexed in C#?
- What are dynamic arrays in C#?
- What are mixed arrays in C#?
- What are jagged arrays in C#?
- How to define multi-dimensional arrays in C/C++?
- How to create arrays dynamically in C#?
- How to initialize jagged arrays in C#?
- How to concatenate Two Arrays in C#?

Advertisements