scanf,strcpy,strlen,strcat等函数在多种编译器中实现编译的方法
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
int num1 = 0;
int num2 = 0;
int sum = 0;
scanf("%d%d", &num1, &num2);
sum = num1 + num2 ;
printf("sum = %d\n", sum);
return 0;
}
1.字面常量
%include <stdio.h>
int main ()
{
int num = 4;
3 ; // 字面常量(数字单独出现时称为常变量)
100 ; // 字面常量
return 0 ;
}
2.const修饰的常变量
#include <stdio.h>
int main()
{
const int num = 4;//const修饰的常变量
printf("%d\n",num);
num = 8 ;
printf("%d\n",num);
return 0;
}
num虽然具有了const 的常属性,但是num任然是个变量
例子:
#include <stdio.h>
int main()
{
int n = 10;
int arr [n] = { 0 }
return 0 ;
}
输出结果出现错误,因为[n]任然具有变量的性质,1.若把[n]换为[10]这样程序能够正常运行,且输出结果为10
2.若在int前添加const,使得n具有了常属性,但是任然具有变量的性质,任然会编译失败
#include <stdio.h>
int main()
{
const int n = 10 ;// n 是变量,但是又有常属性, 所以我们说n 是常变量
int arr [n] = {0} ;
return 0;
}
3.#define 定义的标识符常量
#include <stdio.h>
#define MIN 19
int main ()
{
int arr [ MIN ] = { 0 } ;
printf("%d\n", MIN) ;
return 0 ;
}
4.枚举常量
//枚举---一一列举;
//性别:男, 女, 保密;
//三原色:红 ,黄,蓝 ;
//星期:1,2,3,4,5,6,7;
#include <stdio.h>
enum Color
{
RED,
YELLOW, // RED ,YELLOW ,BLUE 为枚举常量
BLUE
};
int main ()
{
enum Color color = BLUE;
return 0 ;
}