 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 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
Advertisements
 