Search
 
SCRIPT & CODE EXAMPLE
 

CPP

How to pass a multidimensional array to a function in C and C++

1 #include <stdio.h>
 2 
 3 void print_2d_array(int rows, int cols, int *a) {
 4     for(int i = 0; i < rows; ++i) {
 5         for(int j = 0; j < cols; ++j) {
 6             printf("%d ", a[i * cols + j]);
 7         }
 8         printf("
");
 9     }
10 }
11 
12 int main(void) {
13     int arr[][3] = {
14         {1, 2, 3},
15         {4, 5, 6}	
16     };
17 
18     print_2d_array(2, 3, arr[0]);
19 }
Comment

PREVIOUS NEXT
Code Example
Cpp :: Start mongodb community server 
Cpp :: ifstream 
Cpp :: c++ lambda as variable 
Cpp :: time complexity of sorting algorithms 
Cpp :: erase range vector c++ 
Cpp :: pointers c++ 
Cpp :: round c++ 
Cpp :: sum of n natural numbers 
Cpp :: operator overloading in c++ 
Cpp :: if in c++ 
Cpp :: valid parentheses in c++ 
Cpp :: floor and ceil in cpp 
Cpp :: c++ pointers 
Cpp :: C++ switch..case Statement 
Cpp :: pause the console c++ 
Cpp :: sstream c++ 
Cpp :: ue4 endoverlap c++ 
Cpp :: c ++ The output should be (abc),(def),(ghw) 
Cpp :: how to bath without water 
Cpp :: i++ i-- 
Cpp :: c++ graphics online compiler 
Cpp :: #include <iostream #include <stdio.h using namespace std; int main() { int a[5]; a[0]=12; a[1]=13; a[2]=14; a[3]=15; 
Cpp :: convert string to double arduino 
Cpp :: cout ascii art c++ 
Cpp :: argument to number C++ 
Cpp :: Link List Insertion a node 
Cpp :: how to save system function output into a variable in c++ 
Cpp :: CPP Find options passed from command line 
Cpp :: std::ifstream cant read file to large 
Cpp :: c++ regex to validate indian phone number pattern 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =