C语言指针与数组:深入理解与应用
1. 无指针变量传递地址给函数
在某些情况下,我们可以进一步简化代码,移除 main()
函数中的指针变量,直接在函数调用中传递所需的地址。虽然在函数定义中仍需要指针变量作为参数,但在 main()
函数体中可以省略。
操作步骤如下:
1. 将 pointers2.c
复制到 pointers3.c
。
2. 仅修改 main()
函数的主体,代码如下:
int height = 10;
int width = 20;
int length = 40;
printf( "\nValues:\n\n");
showInfo( height , width , length );
printf( "\nUsing address of each named variables...\n\n");
showVariable( "height" , &height );
showVariable( "width " , &width );
showVariable( "length" , &length );
-
showInfo()
和showVariables()
函数保持不变。 - 移除打印
pDimension
信息的 <