c/c++函數指標變數和函數指標參數

來源:互聯網
上載者:User
 
 

導讀

//函數指標:指向函數的指標  
//指標函數:傳回值為指標的函數

//形式1:傳回型別 (*函數指標名)(形參數表)                            (c/c++)
//形式2:typedef 傳回型別 (*新函數指標類型)(形參數表)              (c/c++)
//形式3:typedef 傳回型別 (類名::*新函數指標類型)(形參數表)    (c++   )



如:
int (*p) ( );                // *後面的p表示函數指標變數,它後面有個( )表示該指標變數指向一個函數
typedef  int (*fp)( );  // *後面的fp表示用typedef定義的新函數指標類型,它後面有個( )表示該類型指向一個函數

---------------------------------------------------------------------------------------------------------------------------------------------------

以下是執行個體,
/*  Author:  Eric */
#include<stdio.h>
typedef  int (*fp)(int,int);
int fuc1( int i,int j)
{
    return (i + j);
}

int fuc2(int i,int j,fp p)
{
    return p(i,j);   
}

void main()
{
    fp p = fuc1;   
    printf("%d",fuc2(100,200, p));   
}

在vc, dev c++, turbo c 上測試通過

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.