
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
How to pass a 2D array as a parameter in C?
A 2-D array can be easily passed as a parameter to a function in C. A program that demonstrates this when both the array dimensions are specified globally is given as follows.
Example
#include <stdio.h> const int R = 4; const int C = 3; void func(int a[R][C]) { int i, j; for (i = 0; i < R; i++) for (j = 0; j < C; j++) a[i][j] += 5; ; } int main() { int a[R][C]; int i, j; for (i = 0; i < R; i++) for (j = 0; j < C; j++) a[i][j] = i+j; printf("Initial 2-D array is:
"); for (i = 0; i < R; i++) { for (j = 0; j < C; j++) { printf("%d ", a[i][j]); } printf("
"); } func(a); printf("Modified 2-D array is:
"); for (i = 0; i < R; i++) { for (j = 0; j < C; j++) { printf("%d ", a[i][j]); } printf("
"); } return 0; }
Output
The output of the above program is as follows.
Initial 2-D array is: 0 1 2 1 2 3 2 3 4 3 4 5 Modified 2-D array is: 5 6 7 6 7 8 7 8 9 8 9 10
- Related Articles
- How to pass an array as a URL parameter in Laravel?
- How to pass a function as a parameter in Java
- How to pass a jQuery event as a parameter in a method?
- How to pass a lambda expression as a method parameter in Java?
- How to pass an object as a parameter in JavaScript function?
- How to pass a json object as a parameter to a python function?
- C# Program to pass Parameter to a Thread
- How can I pass a parameter to a setTimeout() callback?
- How to pass entire array as an argument to a function in C language?
- How to dynamically allocate a 2D array in C?
- How to store a 2d Array in another 2d Array in java?
- How to convert a 2D array into 1D array in C#?
- How to create a dynamic 2D array inside a class in C++
- C++ Perform to a 2D FFT Inplace Given a Complex 2D Array
- How to print size of array parameter in a function in C++?

Advertisements