传递数组的大小
#include <stdio.h>#include <stdlib.h>#define SIZEOF(a) ( sizeof a / sizeof a[0] )void printarray( double x[], int );int main(){ double array1[ 100 ]; printf( "The size of array1 = %ld.\n", SIZEOF( array1 )); printf( "The size of array1 = %ld.\n", sizeof array1 ); printf( "The size of array1[0] = %ld.\n\n", sizeof array1[0] ); printarray( array1, SIZEOF( array1 ) ); return EXIT_SUCCESS;}void printarray( double p[], int s ){ int i; // THIS IS WHAT DOESN"T WORK, SO AS A CONSEQUENCE, I PASS THE // SIZE IN AS A SECOND PARAMETER, WHICH I'D RATHER NOT DO. printf( "The size of p calculated = %ld.\n", SIZEOF( p )); printf( "The size of p = %ld.\n", sizeof p ); printf( "The size of p[0] = %ld.\n", sizeof p[0] ); for( i = 0; i < s; i++ ) printf( "Eelement %d = %lf.\n", i, p[i] ); return;}
素胚勾勒不出你
慕尼黑8549860
手掌心
相关分类