As the return value of a function pointer

#include <stdio.h>
#define A 0
int funcA(int a, int b)
{
	return a + b;
}
int  *funcB(int a, int b)
{
	static int c=A;
	c = a + b;
	return &c;
}
int main(int argc, char **argv)
{
	int *p_int, temp;
	p_int = (funcB(2, 5));
	printf("%d\n", *p_int);
	//第二种不推荐
	temp = *funcB(4, 8);
	/*错误写法 &temp=funcB(5,7);*/
	system("pause");
	return 0;
}

Specification writing:

funcB function pointer to a function, the return value address.

Then p_int acceptance instruction pointer return value. Address already exists at this time c p_int pointer, followed by the addition of an asterisk, the address data output p_init referred.
int * p_int;

p_int=*(funcB(2,5));

 

 

 

/ * Error wording & temp = funcB (5,7); * /

Cause: When restatement temp, the address of the variable operating system has been fixed,

Published 29 original articles · won praise 3 · Views 3175

Guess you like

Origin blog.csdn.net/qq_38436175/article/details/104042368