Pass char something[x][y] to function

Hello,

How to pass the char something[8][8] for example
to function

void ( char pass.....)???
You can declare the function in several ways. For example

void f(char s[][8], size_t n );

or

void f( char ( &s )[8][8] );

or

void f( char ( *s )[8][8] );

or void f( char **s, siize_t n. size_t m );

The last declaration requires to convert the argument to the type of the parameter.
Last edited on
and how do u pass it in the main?

print(.....??);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include <iostream>
using namespace std;
void print(char (*s)[8][8] );
int main(){
	
	char board[8][8];
	for(int i=0; i < 8 ; i++){
		for(int k=0; k <8; k++){

			board[i][k] = 'O';
		}


	}


	print(board); 

	

}


void print(char (*s)[8][8] ){
	for(int i=0; i < 8 ; i++){
		for(int k=0; k <8; k++){

			cout <<s[i][k];
		}

		cout << endl;
	}
	


}


print(&board);
print( &board );

1
2
3
4
5
6
7
8
9
10
11
12
13
void print(char (*s)[8][8] ){
	for(int i=0; i < 8 ; i++){
		for(int k=0; k <8; k++){

			cout <<( *s )[i][k];
		}

		cout << endl;
	}
	


}
Last edited on
I forgot to mention one more method:)

template <size_t N = 8, size_t M = 8>
void f( char ( &s )[N][M] );
@vlad
Why the default template arguments? Can they not always be inferred?
@Peter87

@vlad
Why the default template arguments? Can they not always be inferred?


Because in the original post there was shown array char something[8][8].:)
Topic archived. No new replies allowed.