<26> "Understanding" 10-function pointer concept and definition + "mastering" 11-function pointer use +

Source: Internet
Author: User
Tags define function

"Understanding" 10-function pointer concepts and definitions

  The pointer variable holding the first address of the function is the definition of the function pointer variable function pointer variable return value type ( * variable name) (parameter of the function); Declaration of function:  int  sum (int  A,int  b);----> Function pointer int  (*P1) (int          a,int   b);  //  defines a function pointer p1  // P1 can hold the return value is the int type, and there are two parameters, the type of the formal parameter is also the address of the function of type int  //   P1  = sum; // sum is the first address of the function in memory  
#include <stdio.h>floatF1 (intXinty) {    returnx+y;}intSumintAintb) {    returnA +b;}intMainintargcConst Char*argv[]) {            intx=3, y =5; ints =sum (x, y); //Defining function Pointers    int(*p) (intAintb); //Initializing function Pointersp = sum;//the first address of the SUM function//p = F1; not possible .//Note: When defining a function pointer, you do not have to write the parameter name    int(*P1) (int,int ); P1=sum; return 0;}

"Mastering" 11-function pointer use  

#include <stdio.h>intSumintXinty) {        returnx+y; }intJianintXinty) {        returnX-y; }intChengintXinty) {        returnx*y; }intChuintXinty) {    returnx/y;}intMainintargcConst Char*argv[]) {        //use of function pointers//1. Define function Pointers    int(*p) (int,int ); //2. Initialization of function pointersp = sum;//P also points to the SUM function        Switch(3) {         Case 1: P=sum;  Break;  Case 2: P=Jian;  Break;  Case 3: P=Cheng;  Break;  Case 4: P=Chu;  Break; default:             Break; }        //3. Calling functions indirectly with function pointers//(*p) (23,45);    ints = P ( at, $); printf ("%d\n", s); return 0;}
1035

<26> "Understanding" 10-function pointer concept and definition + "mastering" 11-function pointer use +

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.