【发布时间】:2013-02-20 16:33:06
【问题描述】:
我的疑问是:为什么在这段代码中:
/*Asignacion de valores en arreglos bidimensionales*/
#include <stdio.h>
/*Prototipos de funciones*/
void imprimir_arreglo( const int a[2][3] );
/*Inicia la ejecucion del programa*/
int main()
{
int arreglo1[2][3] = { { 1, 2, 3 },
{ 4, 5, 6 } };
int arreglo2[2][3] = { 1, 2, 3, 4, 5 };
int arreglo3[2][3] = { { 1, 2 }, { 4 } };
printf( "Los valores en el arreglo 1 de 2 filas y 3 columnas son:\n" );
imprimir_arreglo( arreglo1 );
printf( "Los valores en el arreglo 2 de 2 filas y 3 columnas son:\n" );
imprimir_arreglo( arreglo2 );
printf( "Los valores en el arreglo 3 de 2 filas y 3 columnas son:\n" );
imprimir_arreglo( arreglo3 );
return 0;
} /*Fin de main*/
/*Definiciones de funciones*/
void imprimir_arreglo( const int a[2][3] )
{
int i; /*Contador filas*/
int j; /*Contador columnas*/
for (i = 0; i <=1; i++)
{
for (j = 0; j <= 2; j++)
{
printf( "%d ", a[i][j] );
}
printf( "\n" );
}
} /*Fin de funcion imprime_arreglo*/
如果不声明 const 之类的矩阵变量,我就无法编译,而在向量中我可以...为什么会出现这种行为?对不起,如果我的英语不好,我会说西班牙语。非常感谢您的回答。
【问题讨论】:
-
什么?你的意思是函数参数?我想你可以,错误是什么?
-
我的编译器告诉我必须修改数组的类型,但这种行为只发生在矩阵而不是向量中,我想知道为什么?