当前位置:网站首页>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 …
边栏推荐
- Liste des boucles de l'interface graphique de défaillance
- 记录:Navicat Premium初次无法连接数据库MySQL之解决
- [Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
- 继承和多态(下)
- Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
- Heap sort [handwritten small root heap]
- How to reduce the shutdown time of InnoDB database?
- MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
- [dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
- [算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
猜你喜欢

系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries

C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
![[算法] 剑指offer2 golang 面试题1:整数除法](/img/e6/f17135207b3540ec58e5a9eed54220.png)
[算法] 剑指offer2 golang 面试题1:整数除法

Redis介绍与使用

平衡二叉树详解 通俗易懂

图书管理系统小练习
![[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K](/img/8c/1b6ba3b1830ad28176190170c98628.png)
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K

The port is occupied because the service is not shut down normally
![Heap sort [handwritten small root heap]](/img/f0/6efda3c6f499a32671a935dd2f21db.png)
Heap sort [handwritten small root heap]

2022 National Games RE1 baby_ tree
随机推荐
Record: the solution of MySQL denial of access when CMD starts for the first time
雇佣收银员【差分约束】
错误: 找不到符号
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
Basic DOS commands
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
2-year experience summary, tell you how to do a good job in project management
Knowledge system of digital IT practitioners | software development methods -- agile
The earth revolves around the sun
121道分布式面试题和答案
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
KF UD分解之UD分解基础篇【1】
[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 9: subarray with product less than k
WSL common commands
记录:Navicat Premium初次无法连接数据库MySQL之解决
The port is occupied because the service is not shut down normally
【干货】提升RTK模糊度固定率的建议之周跳探测
isEmpty 和 isBlank 的用法区别
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire