第四题第四题第四题,,,,,

 

答案A里的&f是存储函数指针的地址,它和函数的地址是不同的,所以A是错误的,其他三个都可以访问到函数fun,所以是对的。

测试代码如下:

参考链接:


https://blog.csdn.net/m0_46569169/article/details/124318184

#include <stdio.h>

int fun(int a){
    return a*a;
} 

int main(void){
    
    int (*f)(int) = fun; // f为指向函数fun的指针 

    
//    printf("A, %p,%p\n",&f,*(&f));  // &f为存储函数指针的地址,这个应该是和函数的地址是不同的 
//// https://baijiahao.baidu.com/s?id=1704243169750261912&wfr=spider&for=pc
//    printf("B, %d,%p\n",f(2),f);  // 通过函数指针变量调用fun函数,等价于调用fun(2) 
//    // https://blog.csdn.net/m0_46569169/article/details/124318184
//    printf("C, %d,%p\n",(&fun)(2),&fun); // &fun等于函数名fun 
//    printf("D, %d,%p\n",(*f)(2),*f);   // 相当于通过函数名调用 
    
    //printf("A, %p\n",&f;  // &f为存储函数指针的地址,这个应该是和函数的地址是不同的 
// https://baijiahao.baidu.com/s?id=1704243169750261912&wfr=spider&for=pc
    printf("B, %d\n",f(2));  // 通过函数指针变量调用fun函数,等价于调用fun(2) 
    // https://blog.csdn.net/m0_46569169/article/details/124318184
    printf("C, %d\n",(&fun)(2)); // &fun等于函数名fun 
    printf("D, %d\n",(*f)(2));   // 相当于通过函数名调用 
    return 0;
} 

img