// declare the variable in C. Datatype variable_name; Datatype variable_name1, variable_name2, vriable_name3; int a, b, d; int _c; char letter; float z ; har str[] = "welcome";
Datatype variable_name; // declaration of variable Variable_name = 10; // define value; Declaration and initialization of variable: Datatype variable_name = value; int a = 10; float x = 5.5; char letter = 'A'; int z = 1, a = 5, c = 2;
/* create a program to display the use of #define processor in C. #include<stdio.h> #include<conio.h> #define PI 3.14 void main() { int radius, area; printf(" Please enter the radius of circle\n"); scanf("%d", &radius); area = PI * radius * radius; printf(" Area of circle is : %d", area); getch(); }
/* create a program to display the use of const keyword in C. */ #include<stdio.h> #include<conio.h> void main() { const int Len = 5; const int Width = 5; int area; area = Len * Width; printf(" Ares of Rectangle is : %d", area); getch(); }
变量 | 常量 |
是在程序中存储数据类型值的变量。 | 它类似于变量,在程序执行期间无法更改。 |
它是一个变量,可以在程序中定义该变量之后 | 它是一个固定变量,在程序中定义变量后就不能更改。 |
变量的值可以根据条件而变化。 | 在常量中,该值不能更改。 |
通常,它在程序中使用int,float,char,string,double等数据类型。 | 可以用两种方式表示: #define预处理程序和const关键字。 |
示例: int a = 5;浮点半径= 5.2;字符'A'; | 示例: const int Len = 5; #define PI 3.14 |