C language-function pointer and function pointer array __ function

Source: Internet
Author: User
#include <stdio.h>
//function pointer 
int fun (void)
{
	printf ("Hello world\n");
	return 0;
}

int main (int argc, const char *argv[])
{
	printf ("main =%p\n", main);
	Int (*p) (void) = fun; 			P 	function pointer: Essence is pointer								
	p (); 							Fun 	Address constant return
	0;
}


#include <stdio.h>
//function pointer array 

//function Sub 
int sub (int a, int b)
{
	printf ("Sub =%d\n", a-b); C22/>return 0;
}
function add 
int Add (int a, int b)
{
	printf ("add =%d\n", a+b);
	return 0;
}
int main (int argc, const char *argv[])
{
	//define an array of function pointers  : Its invocation return value is int, parameter is int,int 
	int (*p[2]) (int, int ); Essence: Array, element: function pointer type												
	p[0] = sub;
	P[1] = add;

	P[1] (10,3);
	P[0] (10,3);
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.