C 語言中有哪些不同型別的常量?
常量是程式執行期間無法被更改的值;它是固定的。
在 C 語言中,一個數字或字元或字元序列稱為常量。並且它可以是任何資料型別。常量也稱為文字。
常量有兩種型別 −
基本常量 − 整數、浮點數和字元稱為基本常量。
派生常量 − 陣列、結構、指標、列舉等稱為派生常量。
語法
const datatype variable;
基本常量的示例
#include<stdio.h>
int main(){
const int height=20;
const int base=40;
float area;
area=0.5 * height*base;
printf("The area of triangle :%f", area);
return 0;
}輸出
The area of triangle :400.000000
派生常量的示例
include<stdio.h>
void main(){
int a;
int *p;
a=10;
p=&a;
printf("a=%d
",a);//10//
printf("p=%d
",p);//address value of p//
*p=12;
printf("a=%d
",a);//12//
printf("p=%d
",p);//address value of p//
}輸出
a=10 p=6422036 a=12 p=6422036
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP