C语言学习

1.#include<stdio.h> //include库函数 standard input output 标准输入输出函数
输入: scanf
#include<stdio.h>
Int main()
{
Int num1=0;
Int num2=0;
Int sum=0;
Scanf(“%d%d”,&num1,&num2); //输入 把0 0放到num1num2的地址内
Sum=num1+num2;
Printf(“sum = %d\n”,sum);
Return 0;
}
输出:printf
2.Char -字符类型 char a=”A”; 向内存申请内存空间
Short age=20;向内存申请两个字节 short申请 16个比特位
%d - 打印整型; %c - 打印字符; %f - 打印浮点数;
%p -以地址的形式打印; %x - 打印16进制数字
Printf(“%d\n”,sizeof(int/short/long/double/char/));看各类型的内存空间。 char -1字节;short-2字节;int-4字节;long-4/8字节
Longlong-8字节; float-4字节;double-8字节;
Bit-比特位 放一个二进制 0 1
Byte-字节 1字节=8个比特位
Kb 1kb=1024个字节
Mb 1mb=1024kb
3. 类型是来创建变量的
局部变量:生命周期在作用域内; 全局变量:生命周期为整个程序。
#include<stdio.h> #include<stdio.h> #include<stdio.h>
Int a=10;//全局 int main() int main()
Int main() { {
{ int a=10; //局部 int a=10;//局部 作用域只在
Printf(“%d\n”,a); printf(“%d\n”,a); } main函数中
} //ok } //ok printf(“%d\n”,a); //error
<C语言中定义变量要放在前面>
4.常量
(1)字面常量:一个数字值3 4
(2)Const修饰的常变量,int赋值后就不可以在修改了
Const int n=10; n为变量加上const 为常变量 依旧为变量
Int arr[n]={0}; // error所以内存无法分配
Int arr[10]={0}; //OK
n=20; //error const修饰不可改变值
(3)#define 定义的标识符常量
#define MAX 10
Int main()
{
Int arr[MAX]={0};
Printf(“%d\n”,MAX);
Return 0;
}
(4)枚举常量(枚举常量不可改变) 枚举关键–enum
Enum
{
Red; //系统内部自动赋值为 0
Yellow; // 1
Blue; // 2
}
Int main()
{
enum Color color=Blue;
Color = Yellow; //变量可以改值
Blue =6; //error 不可改变枚举常量由系统自动赋值 不可改变
Return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值