


This article will help you learn C language and talk about the basic knowledge of C language (data types, variables, functions, arrays, etc.). I hope it will be helpful to everyone!
What is C language
- Simply put
C language is a computer language , widely used in low-level development, using the language to write code programs and solve problems
So for the computer major, C language and learning C language are very important
Computer Language Development
As far as computers are concerned, the initial implementation of binary code (1/0) was achieved by powering on the computer to communicate with the computer and then forming a binary code
But It was too troublesome, so we developed mnemonics (assembly language), and then formed the B language, and then developed the C language
And then various interpreted languages appeared (Java, python, etc.)
Write the first C language code
- Tools
Recommended VS2019 compiler
Basic format
#include<stdio.h> //内是头文件名称;stdio代表standard input output; 即标准输入输出头文件(与后面所执行任务要用的库语言所关联) int main() //主函数,程序的入口(有且只有一个); { //int 代表整型;即表示main函数调用返回整型值 任务; return 0; }</stdio.h>
Data type
char character short (int) short integer type int integer type long (int) long integer type long long (int) long integer type
float single-precision floating-point type double double-precision floating-point type (integer type is used for integers, and floating point type is used for decimals)
There are so many data types, it is for more convenience It’s good to apply for memory space from computer (try to save space and optimize memory )
unit
From the above The memory applied for each data type is: 1 2 4 4 8 4 8 (unit bytes, individual differences vary depending on the number of computers)
Example; short is 2 bytes, which is 16 bits (binary)
Range: the minimum is all 0, which means 0; the maximum is all 1, the range obtained by the weight bit is 2*10^16-1
Variables
- Type
Variables are divided into local variables and global variables
Scope
Local variables: In the local scope where local variables are located
Global variables: the entire project
Life cycle
Local variables: the period starts when entering the local scope and ends when leaving
Global variables: the life cycle of the program
Note: When the defined variable has the same name, the local priority## in the local scope #;
C language and law stipulate thatvariables must be defined at the front of the current code block.
Constant Type of constant in C language:
- Literal constant: 3.14, "abc", etc.
- Constant variables modified by const: const—constant attributes, the essence is constants defined by variables
- #define: Example: #define MAX 100
- Enumeration constants: enum Enumeration: enumerate one by one; Example: enum Sex {male, female, secret}
Function
In the coding process, it is inevitable to encounter the repeated use of a certain set of statements. Creating a function at this time can make coding much easier and faster - simplifying reuse.
- For example, create an addition function (custom)
int Add(int x, int y) { int z = 0; z = x + y; return z; } int main() { int a = 10; int b = 20; int ret = 0; ret = Add(a, b); printf("%d\n", ret) return 0; }
Array
The array is an Grouping a collection of elements of the same type
- Creating an array is also equivalent to applying for space from the computer. It is a connected space with a label
- For this array, its label starts from 0 Initially, the elements in the array are generally accessed in the form of array subscripts
- The array name is also a special address
Operator
Arithmetic: Multiply* Division/Remainder % Addition Subtraction-
Shift (2 Base): First represent the number in binary and shift it, and then represent it into the corresponding number after the shift位操作
- 按位于:两个数以二进制竖着排列,有0则为0,都是1才为1
- 按位或:两个数以二进制竖着排列,有1则为1,都是0才为0
- 按位于:两个数以二进制竖着排列,相同则为0,相异才为1
赋值
注意区别=与==:一个是赋值,一个是判断相等
单目操作
(操作数个数决定是单还是其他,例 1+2:1和2是操作数,为双目操作符)
关系/逻辑/条件
- 解释: 表达式1成立,结果为表达式2,否则为3
逗号表达式
- 解释:从左向右依次计算,结果去最后一个表达式
关键字
字符串
定义
即“ ”中的内容(例:“abc”)
结束标志
- “\0”(\0不做字符串的内容)
- 注:字符串可以存放在字符数组中;C语言无字符串类型
局别
- 示图1中的arr2数组元素型初始化,它的长度未定义,会随机生成,直到遇到“\0”,来结束字符串
求字符串长度
sizeof(arr[])计算内容包括“\0”,算作一个bite
strlen(arr)不包括“\0”,计算字符串内容长度(需要审引库函数—
)
转义字符
\0是一个字符,还有\t,\n等代表不同意思的字符
转义字符则是转变原来的意思
例如你想单纯打印\n,那么则需要在“\n”前再打一个“\”,来转变“\n”原本的意思
注释
注释即用来注明,解释代码步骤的意思,让自己和读者能更好的理解
C语言——/* */ C++——//
- 注意:除了用来解释,还可以删除不需要的代码;注解不能嵌套使用
选择语句
if(条件) 多选择:if(条件) 执行语句; 执行语句; else \\反之 else if(条件) 执行语句; 执行语句; else...
循环
while循环: 初始化; while(条件) { 执行和调整语句;} for循环 for(初始化;条件;调整) { 执行语句; } do while循环 do { 执行和调整语句;} while(条件)
注:while先判断条件,符合再执行语句,而do while循环先执行语句,再判断条件是否再进行循环;在长幅篇的代码中,用for循环比较适合,用while不利于更改如果有需要的话
相关推荐:《C视频教程》
The above is the detailed content of Introduction to C language: talk about basic knowledge (data types, variables, functions, arrays, etc.). For more information, please follow other related articles on the PHP Chinese website!

VScode中怎么配置C语言环境?下面本篇文章给大家介绍一下VScode配置C语言环境的方法(超详细),希望对大家有所帮助!

在C语言中,node是用于定义链表结点的名称,通常在数据结构中用作结点的类型名,语法为“struct Node{...};”;结构和类在定义出名称以后,直接用该名称就可以定义对象,C语言中还存在“Node * a”和“Node* &a”。

c语言将数字转换成字符串的方法:1、ascii码操作,在原数字的基础上加“0x30”,语法“数字+0x30”,会存储数字对应的字符ascii码;2、使用itoa(),可以把整型数转换成字符串,语法“itoa(number1,string,数字);”;3、使用sprintf(),可以能够根据指定的需求,格式化内容,存储至指针指向的字符串。

在c语言中,没有开根号运算符,开根号使用的是内置函数“sqrt()”,使用语法“sqrt(数值x)”;例如“sqrt(4)”,就是对4进行平方根运算,结果为2。sqrt()是c语言内置的开根号运算函数,其运算结果是函数变量的算术平方根;该函数既不能运算负数值,也不能输出虚数结果。

C语言数组初始化的三种方式:1、在定义时直接赋值,语法“数据类型 arrayName[index] = {值};”;2、利用for循环初始化,语法“for (int i=0;i<3;i++) {arr[i] = i;}”;3、使用memset()函数初始化,语法“memset(arr, 0, sizeof(int) * 3)”。

c语言合法标识符的要求是:1、标识符只能由字母(A~Z, a~z)、数字(0~9)和下划线(_)组成;2、第一个字符必须是字母或下划线,不能是数字;3、标识符中的大小写字母是有区别的,代表不同含义;4、标识符不能是关键字。

c语言编译后生成“.OBJ”的二进制文件(目标文件)。在C语言中,源程序(.c文件)经过编译程序编译之后,会生成一个后缀为“.OBJ”的二进制文件(称为目标文件);最后还要由称为“连接程序”(Link)的软件,把此“.OBJ”文件与c语言提供的各种库函数连接在一起,生成一个后缀“.EXE”的可执行文件。

c语言计算n的阶乘的方法:1、通过for循环计算阶乘,代码如“for (i = 1; i <= n; i++){fact *= i;}”;2、通过while循环计算阶乘,代码如“while (i <= n){fact *= i;i++;}”;3、通过递归方式计算阶乘,代码如“ int Fact(int n){int res = n;if (n > 1)res...”。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
