当前位置:网站首页>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 …
边栏推荐
- Error: symbol not found
- 面渣逆袭:Redis连环五十二问,三万字+八十图详解。
- C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
- [算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
- Music playback (toggle & playerprefs)
- One article to get UDP and TCP high-frequency interview questions!
- Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
- 继承和多态(上)
- Record: I accidentally wrote a recursion next time
- Answer to "software testing" exercise: Chapter 1
猜你喜欢
[算法] 剑指offer2 golang 面试题10:和为k的子数组
[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
FGUI工程打包发布&导入Unity&将UI显示出来的方式
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K
[algorithm] sword finger offer2 golang interview question 5: maximum product of word length
Redis介绍与使用
MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
2022国赛Re1 baby_tree
阿里云一面:并发场景下的底层细节 - 伪共享问题
随机推荐
wsl常用命令
FairyGUI条子家族(滚动条,滑动条,进度条)
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
[GNSS] robust estimation (robust estimation) principle and program implementation
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
Containers and Devops: container based Devops delivery pipeline
2年经验总结,告诉你如何做好项目管理
[algorithm] sword finger offer2 golang interview question 1: integer division
Experience summary of autumn recruitment of state-owned enterprises
基本Dos命令
【rtklib】在rtk下使用抗差自适应卡尔曼滤波初步实践
图书管理系统小练习
国企秋招经验总结
RTKLIB: demo5 b34f. 1 vs b33
Usage differences between isempty and isblank
[Chongqing Guangdong education] Shandong University College Physics reference materials
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
GNSS positioning accuracy index calculation
初识C语言(下)
Application architecture of large live broadcast platform