inline;static

本文展示了C++中函数指针的应用,通过定义函数指针数组并调用数组内的函数来实现不同函数的执行,同时展示了常量volatile变量和函数指针的交互作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// FunsPointArry.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

inline int f1(int a)
{
	static int counter=0;
	printf("f1:%x,%d\n",&counter,++counter);
	printf("f1:%x\n",f1);
	return a;
}
inline  int f2(int a)
{
	printf("f2:%x\n",f2);
	return a;
}
inline int f3(int a)
{
	printf("f3:%x\n",f3);
	return a;
}

typedef int (*Fii)(int a);

int main(int argc, char* argv[])
{
	Fii fsArry[3];
	fsArry[0]=f1;
	fsArry[1]=f2;
	fsArry[2]=f3;
	for(int i=0;i<3;i++)
		fsArry[i](i);
	printf("=================\n");
	f1(0);f2(1);f3(2);
	printf("=================\n");
	f1(0);f1(1);f1(2);
	printf("=================\n");
	const volatile int b=9;
	printf("b=:%d\n",b);
	//b=10;
	int bb=10;
	int* volatile pb=&bb;
	*pb+=1;
	printf("*pb=:%d\n",*pb);
	return 0;
}
/*
f1:427e34,1
f1:401005
f2:40100f
f3:40100a
=================
f1:427e34,2
f1:401005
f2:40100f
f3:40100a
=================
f1:427e34,3
f1:401005
f1:427e34,4
f1:401005
f1:427e34,5
f1:401005
=================
b=:9
*pb=:11
Press any key to continue
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值