在C语言中,变量是存储某种形式的数据的存储位置。不同的变量需要应用一组操作的不同内存量。
变量名不能以数字开头。它可以由字母,数字,下划线“ _”组成。
这是用C语言声明变量的语法,
type variable_name;
这是用C语言声明的多变量的语法,
type variable_name1, variable_name2,variable_name3;
以下是C语言变量的示例,
#include <stdio.h>
int main() {
char a1 = 'H';
int b = 90, c = 150;
float _d = 3.4;
printf("Character value : %c\n",a1);
printf("Integer value : %d\t%d\n",b,c);
printf("Float value : %f",_d);
return 0;
}输出结果
Character value : H Integer value : 90150 Float value : 3.400000
关键字是C语言中预定义的保留字,并且每个字都与特定功能相关联。这些词帮助我们使用C语言的功能。它们对编译器有特殊的意义。
C中总共有32个关键字。
| auto | double | int | struct |
| break | else | long | switch |
| case | enum | register | typedef |
| char | extern | return | union |
| continue | for | signed | void |
| do | if | static | while |
| default | goto | sizeof | volatile |
| const | float | short | unsigned |
这是C语言中关键字的示例,
#include <stdio.h>
int main() {
//char,int和float是关键字,并用作数据类型
char c = 'H';
int b = 6, c;
float _d = 7.6;
//if和else是检查b值的关键字
if(b<5)
printf("Character Value : %c",a1);
else
printf("Float value : %f",_d);
return 0;
}输出结果
Float value : 7.600000