当前位置:网站首页>C语言(1)
C语言(1)
2022-07-30 05:39:00 【代码陈帅】
一、第一个简单的c程序:
#include<stdio.h>
int main() {
//printf是库函数,库函数的使用需要包含头文件的
printf("holle world\n"); //括起来的叫字符串
return 0;
}#表示预处理命令,需写在开头,这是语法所规定的。
include称为文件包含命令,其作用是把尖括号<>或引号“”内指定的文件包含到本程序中来,成为本程序的一部分,被包含的文件通常是由系统提供的,其扩展名为.h,因此称为头文件。
stdio=stdio std input output 标准输入输出 .h=header
main是主程序的意思,是程序的入口,有且仅有一个。
{}花括号是紧跟主程序后面的,{}表示里面要写的内容
return 0 表示返回值为0,表示程序的正常结束。
二、数据类型
char //字符数据类型
short //短整型
int //整形
long //长整型
longlong //更长的整形
float //单精度浮点数
double //双精度浮点数float和double的区别:float精度低,double精度高
每种类型的大小是多少:
#include<stdio.h>
int main() {
printf("%d\n", sizeof(char)); //1
printf("%d\n", sizeof(short)); //2
printf("%d\n", sizeof(int)); //4
printf("%d\n", sizeof(long)); //4
printf("%d\n", sizeof(long long)); //8
printf("%d\n", sizeof(double)); //8
printf("%d\n", sizeof(float)); //4
return 0;
}
单位是字节,byte,存一个二进制数1或0需要一个bit位。1byte=8bit, 1KB=1024byte,1MB=1024KB,1GB=1024MB,1TB=1024GB。
类型其实是用来创建变量的:
int age=20;
float weight=55.6f
类型 变量名=数值。
3 全局变量和局部变量:
#include <stdio.h>
int a= 2019;//全局变量
int main()
{
int b= 2018;//局部变量
printf("b= %d\n", b);
//下面定义的a会不会有问题?
int a= 2020;//局部变量
printf("a= %d\n", a);
return 0; }
//局部变量和全局变量的名字可以相同,当我们既可以使用全局变量又可以使用局部变量的时候,局部变量优先
边栏推荐
- [GStreamer] The name of the plugin should match GST_PLUGIN_DEFINE
- 2022年SQL经典面试题总结(带解析)
- Socket通信编程
- 字符串(一) 哈希
- 多进程实现并发服务器
- MySQL fuzzy query performance optimization
- Falling ants (Peking University entrance exam questions)
- 【图像检测】基于灰度图像的积累加权边缘检测方法研究附matlab代码
- Teach you to completely uninstall MySQL
- MySQL database basics (a systematic introduction)
猜你喜欢

SOA(面向服务架构)是什么?

PyCharm usage tutorial (more detailed, picture + text)

What is SOA (Service Oriented Architecture)?
![[Mysql] DATEDIFF function](/img/cd/7d19e668701cdd5542b6e43f4c2ad4.png)
[Mysql] DATEDIFF function

208.实现Trie树(字典树与哈希表实现)

240.搜索二维矩阵II

Qt实现单击或双击QTableWidge/View表头进行排序

安装Nuxt.js时出现错误:TypeError:Cannot read property ‘eslint‘ of undefined
![[Image detection] Research on cumulative weighted edge detection method based on grayscale image with matlab code](/img/c1/f962f1c1d9f75732157d49a5d1d0d6.png)
[Image detection] Research on cumulative weighted edge detection method based on grayscale image with matlab code

50道SQL练习题(刷完直接进大厂)
随机推荐
[Koltin Flow (2)] The end operator of the Flow operator
flask-socketio实现的网页聊天室(一)
MySQL 灵魂 16 问,你能撑到第几问?
cmd (command line) to operate or connect to the mysql database, and to create databases and tables
Navicat cannot connect to mysql super detailed processing method
C语言自定义类型一网打尽(结构体、位段/位域、枚举、联合体)
2022年SQL大厂高频实战面试题(详细解析)
Personal blog system (with source code)
MySQL stored procedure
[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及
np.argsort()函数详细解析
机器学习—梯度下降Gradient Descent Optimization—c语言实现
k折交叉验证(k-fold Cross-validation)
524.通过删除字母匹配到字典里最长单词
CISP-PTE Zhenti Demonstration
数据操作 / 数据预处理
list(列表)和array(数组)的区别
cross_val_score的用法
面试前需要巩固的算法知识点(自用,更新中)
[Koltin Flow (1)] Five ways to create flow