Array[]][] pass through functions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Array[]][] pass through functions

How can i pass multdimensional arrays through functiones?

7th Nov 2016, 9:20 AM
Maximilian Schmitt-Egenolf
Maximilian Schmitt-Egenolf - avatar
3 Answers
0
#include <iostream> using namespace std; void foo(int a[][3]) { for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { cin>>a[i][j]; } } for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { cout<<a[i][j]; } cout<<endl; } } int main() { int a[3][3]; foo(a); return 0; } In the function parameter, you can skip the dimension of array.
7th Nov 2016, 9:55 AM
kamal joshi
kamal joshi - avatar
0
How do i solve this code? // TicTacToe.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <stdlib.h> #include <iostream> using namespace std; string** makeGridd() { // playboard string** board = new int[3][3]; string** board = { { " ", " ", " " }, { " ", " ", " " }, { " ", " ", " " }, }; return board; } void printGrid(string board[][3]) { //printsgrid cout << board[0][0] << "|" << board[1][0] << "|" << board[2][0] << endl; cout << "-+--+-" << endl; cout << board[0][1] << "|" << board[1][1] << "|" << board[2][1] << endl; cout << "-+--+-" << endl; cout << board[0][2] << "|" << board[1][2] << "|" << board[2][2] << endl; } int main() { string** makeGridd(); printGrid(board); int b; cin >> b; return 0; }
7th Nov 2016, 11:49 AM
Maximilian Schmitt-Egenolf
Maximilian Schmitt-Egenolf - avatar
0
This is how you pass them: Passing Arrays to functions Passing onedimensional array void printArray(int arr[], int size) { //statements; } printArray(printArray, 3); Passing multidimensional Array void printMArray(int(*A)[cols]) { //statements; } printMArray(MultiDArray);
16th Nov 2016, 1:38 PM
Maximilian Schmitt-Egenolf
Maximilian Schmitt-Egenolf - avatar