当前位置:网站首页>First acquaintance with C language (Part 1)
First acquaintance with C language (Part 1)
2022-07-06 13:07:00 【犇犇犇犇犇犇犇】
Here I will give you a brief introduction C Language what we need to learn , Let's have a preliminary understanding .
C Language is a structured programming language , What is structured , That is to say : Sequential structure , Selection structure , Loop structure , Everything in life is the combination, nesting and repetition of these structures . therefore C Language can solve problems in life through programming .
The development of programming language : Machine language is binary – Assembly language people program better through some mnemonics –B Language –C Language , At this time C Language is already a high-level language .
C In language, we need to understand
- Variable
- Constant
- data type
- The scope and life cycle of variables
- Comment and escape characters
- keyword
- Array
- function
- The pointer
- Selection structure
- Loop structure
- Structure
Variables and constants
Look at the following code
//1. Literal constants
//2.const Modified constant variable
//3. adopt define Defined constant
//4. Enumeration defined constants
enum Color
{
Red=0,
Green=0,
Blue=0,
};
#define Max 100
int main()
{
//30;
//3.14;
//'W';// character
//"abc";
stay C In language ,const Embellished a, It's essentially a variable , But it can't be modified directly , There are properties of constants
//const int a = 10;
//a = 20;
//printf("%d ", a);
//const int n = 10;
//int arr[n] = { 0 };// At this time, the error is that the expression must contain a constant value
//return 0;
//Max = 10;// When you want to modify define When defining variable values , You're going to report a mistake .
//printf("%d\n", Max);
//Red = 10; // You can see that there will be define The same mistake
printf("%d\n", Red);
return 0;
}
int main()
{
int a = 10;
a = 20;
printf("%d\n", a);
// This is the variable that can be changed
return 0;
}
data type
// What are the data types
// character
// integer Short integer Long integer Longer integer
// floating-point Single precision floating point Double precision floating point
int main(){
printf("%d\n", sizeof(char));// byte --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(float));// --4
printf("%d\n", sizeof(double));// --8
return 0;
}
The life cycle and scope of variables
// Scope of variable
//1. local variable
// From the function that created it to the end of this function
//2. Global variables
// The scope of global variables is the whole project
// Life cycle of variable
// local variable : Enter the scope and start , Out of scope end
// Global variables : The whole life cycle of the program
int main(){
int a = 10;
{
//int a = 10;
printf("%d\n", a);
}
printf("%d", a);
return 0;
}
Comment and escape characters
/* /* int main() { This is a C The annotation style of language */
return 0;
}*/
//int main()
//{
// This is a C++ The annotation style of
// return 0;
//}
// current C Language has also introduced // This style
/**/C This annotation style of language
shortcoming : You can't nest
C++ The annotation style of
advantage : Convenient single line notes , You can also comment multiple lines
Escape characters, you can search the Internet to understand it by yourself. There is no more introduction here , But leave a question for everyone , See if you can do it right
int main()
{
// What will the compiler output
printf("%s\n","C:\\test\test.c");
printf("%d\n", sizeof("C:\\test\test.c\x069"));
return 0;
}
Array
int main()
{
int arr[10] = {
0 };
// int Represents the array type arr Represents the array name
//10-- Array size {0}--- All ten elements in the array are assigned zero
return 0;
}
function
// Write a sum of two numbers
int ADD(int x, int y)
{
//int The return type of the function
//ADD Function name
//int x,int y The parameters of the function
//{
// return x + y; These three lines are the function body
//}
return x + y;
}
int main(){
// establish
int num1 = 0;// Variable initialization
int num2 = 0;
// Input
scanf("%d %d", &num1, &num2);
// Sum up
//int sum = num1 + num2;
int sum = ADD(num1, num2);
// Output
printf("%d", sum);
return 0;
}
To be continued …
边栏推荐
- 记录:newInstance()过时的代替方法
- Lean product development - Lean Software Development & lean product development
- PRIDE-PPPAR源码解析
- [algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
- 第一人称视角的角色移动
- 【GNSS】抗差估计(稳健估计)原理及程序实现
- MySQL shutdown is slow
- What are the functions and features of helm or terrain
- Record: newinstance() obsolete replacement method
- [算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
猜你喜欢
[algorithm] sword finger offer2 golang interview question 2: binary addition
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
rtklib单点定位spp使用抗差估计遇到的问题及解决
地球围绕太阳转
染色法判定二分图
阿里云一面:并发场景下的底层细节 - 伪共享问题
Heap sort [handwritten small root heap]
抽象类和接口
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
服务未正常关闭导致端口被占用
随机推荐
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
FGUI工程打包发布&导入Unity&将UI显示出来的方式
[rtklib 2.4.3 B34] version update introduction I
How do architects draw system architecture blueprints?
[算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和
Error: sorting and subscript out of bounds
Lean product development - Lean Software Development & lean product development
记录:初次cmd启动MySQL拒接访问之解决
Redis介绍与使用
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
服务未正常关闭导致端口被占用
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
Basic DOS commands
Shortest Hamilton path (pressure DP)
NovAtel 板卡OEM617D配置步骤记录
Problems and solutions of robust estimation in rtklib single point location spp
Record: Navicat premium can't connect to MySQL for the first time