/*C語言 使用const的範例*/
#include<stdio.h>
#include<stdlib.h>

const double PI=3.14;
/*宣告PI為double型態的常數*/
double function(void);
/*宣告function()的原型*/

int main(void)
{
    /*若在此處宣告PI=3.1416,
    則編譯器會發生錯誤or執行宣告為const的值*/
    printf("PI=%.2f,Area of a circle=%.2f\n", PI, function());

    system("pause");
    return 0;
}

double function(void)
{
    int r = 2;
    double area=0;

    return area = PI * r * r;
}

結果為:

擷取.PNG

arrow
arrow
    創作者介紹
    創作者 愛學習 的頭像
    愛學習

    愛學習

    愛學習 發表在 痞客邦 留言(0) 人氣()