函数之间二维数组多种表示方法的传递问题
被搞的有点迷糊。。。。
代码1
#include <stdio.h>
#define ROWS 2
#define COLS 100
void print_alldata(char *szdata[], int rows);
int main(void )
{
char szdata[ROWS][COLS]={
"this is the first line!",
"this is the second line!"
};
print_alldata(szdata, ROWS);
return 0;
}
void print_alldata(char *szdata[], int rows)
{
for(int i = 0; i < rows; ++i)
puts(szdata[i]);
}
#include <stdio.h>
#define ROWS 2
#define COLS 100
void print_alldata(char *szdata[], int rows);
int main(void )
{
char *szdata[ROWS]={
"this is the first line!",
"this is the second line!"
};
print_alldata(szdata, ROWS);
return 0;
}
void print_alldata(char *szdata[], int rows)
{
for(int i = 0; i < rows; ++i)
puts(szdata[i]);
}
#include <stdio.h>
#define ROWS 2
#define COLS 100
void print_alldata(char szdata[][COLS], int rows);
int main(void )
{
char szdata[ROWS][COLS]={
"this is the first line!",
"this is the second line!"
};
print_alldata(szdata, ROWS);
return 0;
}
void print_alldata(char szdata[][COLS], int rows)
{
for(int i = 0; i < rows; ++i)
puts(szdata[i]);
}
#include <stdio.h>
#define ROWS 2
#define COLS 25
void print_alldata(char *szdata, int );
int main(void )
{
char szdata[ROWS][COLS]=
{
{"this is the first line!\n"},
{"this is the second line!\n"}
};
print_alldata(szdata,50);
return 0;
}
void print_alldata(char *szdata, int rows)
{
int i;
for(i = 0; i < rows; ++i)
printf("%c",szdata[i]);
}
using namespace std;
int main()
{
char test[2][10] = {"test", "other"};
cout << sizeof(test) << endl; //20
cout << sizeof(test[0]) << endl; //10
cout << sizeof(test[1]) << endl; //10
}