Hola que tal. Lo que pasa es que en este codigo:
/*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++)
{
}
}
} /*Fin de funcion imprime_arreglo*/
Cuando compilo de esa manera me da estos errores mi compilador:
ArreglosBidimensionales.c: In function ‘main’:
ArreglosBidimensionales.c:16:3: warning: passing argument 1 of ‘imprimir_arreglo’ from incompatible pointer type [enabled by default]
ArreglosBidimensionales.c:5:6: note: expected ‘const int (*)[3]’ but argument is of type ‘int (*)[3]’
ArreglosBidimensionales.c:19:3: warning: passing argument 1 of ‘imprimir_arreglo’ from incompatible pointer type [enabled by default]
ArreglosBidimensionales.c:5:6: note: expected ‘const int (*)[3]’ but argument is of type ‘int (*)[3]’
ArreglosBidimensionales.c:22:3: warning: passing argument 1 of ‘imprimir_arreglo’ from incompatible pointer type [enabled by default]
ArreglosBidimensionales.c:5:6: note: expected ‘const int (*)[3]’ but argument is of type ‘int (*)[3]’
Pero cuando compilo quitandole el calificador de tipo const al prototipo y definicion de funciones es decir asi:
/*Prototipos de funciones*/
void imprimir_arreglo( int a[2][3] );
.......
/*Definiciones de funciones*/
void imprimir_arreglo( int a[2][3] )
{
Si puedo compilar correctamente.
Por que pasa eso? Por que en arreglos unidimensionales si puedo compilar con el calificador const y en los bidimensionales no? Alguien me puede ayudar con esta duda?
Por cierto uso el compilador GNU GCC.
Agradecimientos por adelantado.