1.常量和变量
#include <stdio.h>
#define MY_AGE 10000
const int MY_AGE1 = 10000;//推荐方法
int main() {
int a = 10;
printf("The num is %d \n",a);
a = 11;
printf("The num is %d \n",a);
printf("My age is : %d\n",MY_AGE);
printf("My age is : %d\n",MY_AGE1);
return 0;
}
2.整型数据
#include <iostream>
int main() {
int a = 10;
int b = -10;
long long c = 20;
printf("a=%d,b=%d,c=%lli\n", a, b, c);
int d = 0b100;//二进制
int e = 0xB;//十六进制
int f = 010;//八进制
printf("d=%d,e=%d,f=%d\n", d, e, f);
unsigned int g = 12;
printf("g=%d\n", g);
//_t结尾 所有平台一样
int32_t h = 10;
int8_t i = 127;//-128-----127
uint8_t j = 200;//0------255
printf("h=%d,i=%d,j=%d\n", h, i, j);
return 0;
}
3.实型数据
#include <iostream>
int main() {
float a = 3.1;//单精度,4字节,32位
double b = 3.1;//双精度,8字节,64位
long double c = 3.1;//长双精度,16字节,128位
printf("a=%f,b=%f,c=%Lf\n", a, b, c);
return 0;
}
4.字符型数据
#include <iostream>
int main() {
printf("Hello\nWorld\n");//换行
printf("Hello\rWorld\n");//回车
printf("Hello\bWorld\n");//退格
printf("Hello\tWorld\n");//制表
printf("Hello\fWorld\n");//换页
printf("\\,\"\n");
printf("length of char : %d\n", (int) sizeof(char));
char ch1 = 'a';
char ch2 = 'A';
printf("%d,%d\n", ch1, ch2);
printf("%c\n", ch2 + 32);
return 0;
}
5.typedef自定义
#include <iostream>
typedef int64_t m_long;
typedef char m_char;
typedef uint8_t m_char1;
int main() {
m_long a = 20;
printf("%d\n", a);
m_char b = 'A';
printf("%c\n", b);
m_char1 c = 'c';
printf("%c\n", c);
return 0;
}