#include <stdio.h> int main(void){ int n = 6; int square(int num); int (*fptr)(int); //声明函数指针 fptr = square; //初始化函数指针 printf("%d square is %d.\n", n, fptr(n)); return (0); } int square(int num){ return (num * num); }
#include <stdio.h> double square(double x); // 函数原型 double (*ptr)(double x); // 声明函数指针 int main(void){ ptr = square; // 让指针指向square() //用两种方式调用square() printf("%f %f\n", square(6.6), ptr(6.6)); return 0; } double square(double x){ return x * x; }
时间: 2024-12-29 05:41:22