当前课程知识点:C Programming > Chapter 3 Programming in C > 3.1 Simple Structure and Identifier of C Language Program > 3.1 Simple Structure and Identifier of C Language Program.mp4
大家好
我是云南大学信息学院的丁海燕老师
欢迎走进C语言程序设计课堂
今天我们讲解C语言程序的简单结构和标识符
下面介绍C语言程序的简单结构
例3.1输入两个整数
输出两个数的和
请看源程序
int main(void)
int a,b
定义整型变量a,b
scanf
为整型变量a,b输入值
Printf
输出a加b的和
运行该程序时
假设从键盘分别输入3和7两个整数后
计算机输出结果为10
例3.2 输入两个整数
输出平均值
请看源程序
{ int a,b; float c;
定义整型变量a,b
和实型变量c
Scanf
为整型变量a,b输入值
c = avg(a,b)
表示调用avg函数
求a和b的平均值
printf语句输出平均值c
程序运行时
输入4和9两个整数
调用函数avg求出平均值为6.5
说明如下
1.一个C语言源程序可以由一个或多个源文件组成
2.每个源文件可由一个或多个函数组成
每个函数完成相对独立的功能
函数是C程序的基本单位
3.一个源程序不论由多少个文件组成
都有一个且只能有一个main函数
即主函数
C程序总是从main函数开始执行并在主函数中结束
其它函数都是在执行main()函数时通过调用来执行
4.源程序中可以有预处理命令
包括include 命令
define命令
预处理命令通常应放在源文件或源程序的最前面
5.每一个说明
每一个语句都必须以分号结尾
但预处理命令
函数首部和花括号}之后不加分号
6.一个函数由函数首部和函数体组成
函数首部
例如main()
指定函数名
函数参数及其类型
函数体必须括在{}之内
7.注释可以出现在程序的任何位置
用 /* 和 */ 括起来
必须成对出现
“/”和“*”之间不能有空格
注释部分对程序的运行结果不产生任何影响
也不会被C语言编译程序所编译
也可用“//”来注释一行
程序的基本结构和格式如下
一个C源程序有且只能有一个main函数
称为主函数
C程序总是从main函数开始执行并在主函数结束
其它函数都是在执行main()函数时
通过被调用来执行的
C语言由函数构成
每个函数由函数首部和函数体组成
函数首部指定函数名
函数参数
返回值类型
函数体从{开始,到}结束
函数体内有语句
C语言书写格式自由
习惯小写字母
缩进格式
以;表示语句结束
一条语句可以写在多行上完成
一行中也可以写多条语句
下面介绍一下C语言的标识符
标识符是由字母
下划线和数字组成的字符序列
并且首字母不能是数字
用于程序中的变量
符号常量
数组
函数
数据类型等操作对象的名字
在C语言中标识符分为关键字
预定义标识符和用户标识符三类
第一种 关键字或称保留字
它属于C语言预先规定的一批标识符
它们在程序中代表着固定的含义
并且不能另作他用
C语言定义了32个关键字
分为如下几类
①数据类型标识符
char、int、float
double、short、long
void、signed、unsigned等等
②存储类别
auto、static、register、extern
③语句命令字
break、case、continue等等
④运算符sizeof
第二类是预定义标识符
它是在C语言中
预先定义并具有特定含义的标识符
例如库函数名(scanf、printf)
编译预处理命令(include、define)等
C语言允许用户把这类标记符另作他用
但这将使这些标识符失去系统原定的用途
三 用户定义标识符
由用户根据需要定义的标识符
例如变量名
数组名
函数名等
例如将变量命名为a
将数组命名为score
将函数命名为add等
注意
关键字必须用小写字母
用户标识符不能与C语言关键字相同
否则编译出错
用户标识符最好不与常用的预定义标识符相同
否则将会导致该标识符
失去系统原有含义并可能引起运行出错
用户标识符对大小写敏感
如a与A代表不同的对象
定义用户标识符时应做到“见名知义”
在大型软件的开发过程中
常用匈牙利命名法来定义标识符
用户标识符由字母
下划线和数字组成的字符序列
并且首字母只能是字母或下划线
不能是数字
好了
同学们
C语言程序的简单结构
和标识符我们就学到这儿
下节课再见
-1.1 The development and characteristics of C language
--1.The development and characteristics of C language .mp4
--1.1 Self test questions
-1.2 A simple C Language program
--1.2 A simple C Language program.mp4
--【Source program】 Example 1.1 output a line of text Hello, world! "
--【Source program】 Example 1.2 program composed of multiple functions, find the larger of two integers
--1.2 Self test questions
-1.3 Program, Programming Language and C Program Running Steps
--1.3 Program, Programming Language and C Program Running Steps.mp4
--Running steps of C source program in CodeBlocks
--1.3 Self test questions
-chapter 1 Self-Test
-2.1 The Concept and Description of Algorithms
--2.1 The Concept and Description of Algorithms.mp4
--2.1 Self test questions
-2.2 Examples of Simple Algorithms, Computational Thinking and Structured Programming
--2.2 Examples of Simple Algorithms, Computational Thinking and Structured Programming.mp4
--2.2 Self test questions
-Chapter 2 Self test questions
-3.1 Simple Structure and Identifier of C Language Program
--3.1 Simple Structure and Identifier of C Language Program.mp4
--【Source program】 Example 3.1 input two integers and output the sum of two numbers.
--【Source program】 Example 3.2 input two integers and output the average value.
--【Source program】 Example 3.3 output the value of the character variable.
--3.1 Self test questions
-3.2 Constants, Variables and Assignments
--3.2 Constants, Variables and Assignments.mp4
--3.2 Self test questions
-3.3 Arithmetic, assignment, increment and decrement operators
--3.3 Arithmetic, assignment, increment and decrement operators.mp4
--3.3 Self test questions
-3.4 Conditions, commas, addresses, byte operators, and mixed operations among various numerical data
--3.4 Conditions, commas, addresses, byte operators, and mixed operations among various numerical data
--【Source program】 example of sizeof
--3.4 Self test questions
-3.5 Input and Output Examples and Character Input and Output
--3.5 Input and Output Examples and Character Input and Output.mp4
--【Source program】 Example. Find the root of quadratic equation of one variable.
--【Source program】 Example 1. Successively output three characters of BOY.
--【Source program】Example 2. Input 3 characters of BOY from the keyboard and output them to the screen
--3.5 Self test questions
-3.6 Formatted output printf function
--3.6 Formatted output printf function.mp4
--【Source program】 Example 3.4 output of integer data.
--【Source program】 Example 3.5 real data output.
--【Source program】 Example 3.6 character data output.
--【Source program】 Example 3.7 uses %s to output a string.
--3.6 Self test questions
-3.7 Formatted input scanf function
--3.7 Formatted input scanf function.mp4
--【Source program】 Example 3.8 Input and output integer data
--【Source program】Example 3.9 Input and output single precision and double precision real data.
--【Source program】Example 3.10 input and output character data.
--【Source program】Example 3.11 input and output string.
--3.7 Self test questions
-3.8 Basic Data Types of C Language
--3.8 Basic Data Types of C Language.mp4
--3.8 Self test questions
-Chapter 3 Self test questions
-Operator and expression self test questions
-4.1 Relational operators, logical operators, and if statements
--4.1 Relational operators, logical operators, and if statements.mp4
--【source example】Example 4.1 Find the root of the quadratic equation of one variable.
--【Source program】Example 4.2 Input two real numbers and output them from small to large.
--4.1 Self test questions
-4.2 Switch Statement
--【Source program】Example 4.3 uses switch statement to implement simple menu program
--【Source program】Example 4.4 converts centesimal score into the corresponding grade system score.
--4.2 Self test questions
-4.3 Examples of Selection Structural Programs
--4.3 Examples of Selection Structural Programs.mp4
--【Source program】 Example 4.5 determines whether a year is a leap year.
--【Source program】 Example 4.6 find the solution of quadratic equation of one variable.
--【Source program】Example 4.7 calculate the transportation cost for the user.
--4.3 Self test questions
-Chapter 4 Self test questions
-5.1 While and Do-While Statement
--5.1 While and Do…while statement.mp4
--【Source program】example 5.1 Use while statement to find 1 + 2 + 3 + +100
--【Source program】example 5.2 using do while statement to find 1 + 2 + 3 + +100
--5.1 Self test questions
-5.2 For Statement
--【Source program】example 5.3 Use for loop to find 1 + 2 + 3 +100
--5.2 Self test questions
-5.3 Change the State of Loop Execution and Nested Loop
--5.3 Change the state of loop execution and nested loop .mp4
--【Source program】example 5.4 collecting charity donations
--【Source program】example 5.5 output a number between 100 and 200 that cannot be divided by 3.
--【Source program】multiplication table
--【Source program】example 5.6 Output the following 4*5 matrix.
--5.3 Self test questions
-5.4 Loop Structure Program example 1
--5.4 Loop structure program example 1.mp4
--5.4 Self test questions
-5.5 Loop Structure Program example 2
--5.5 Loop structure program example 2.mp4
--【Source program】example 5. Output the following figure.
--【Source program】example6. The problem of 100 chickens and 100 coins
--【Source program】example 7. Find the approximate value of PI
--5.5 Self test questions
-Chapter 5 Self test questions
-6.1 Definition, Reference and Initialization of One-Dimensional Arrays
--6.1 Definition, Reference of One-Dimensional Arrays.mp4
--6.1 Self test questions
-6.2 One-Dimensional Array Programming
--6.2 One-Dimensional Array Programming.mp4
--【Source program】example 1. Fibonacci sequence
--【Source program】example 2. Find the maximum value and the minimum value.
--【Source program】example 3 exchanging array elements in reverse order.
--【Source program】example 4. Bubble sorting.
--6.2 Self test questions
-6.3 Definition, Reference and Initialization of Two-Dimensional Arrays
--6.3 Definition, Reference of Two-Dimensional Arrays.mp4
--6.3 Self test questions
-6.4 Two-Dimensional Array Programming
--6.4 Two-Dimensional Array Programming.mp4
--【Source program】example 1. Get the average score of each subject.
--【Source program】Example 2. The elements of row and column of a 2D array are interchanged
--6.4 Self test questions
-6.5 Definition, initialization and input and output of character arrays
--6.5 Definition, initialization and input and output of character arrays .mp4
--【Source program】Example 6.6 Output a known string.
--【Source program】Example 6.7 Output a diamond.
--【Source program】Example 6.10 Sorting of strings.
--6.5 Self test questions
-6.6 String Processing Function
--6.6 String Processing Function.mp4
--6.6 Self test questions
-6.7 Character Array Programming
--6.7 Character Array Programming.mp4
--6.7 Self test questions
-Chapter 6 Self test questions
-7.1 Function Concept and How to Define and Call Functions
--7.1 Function Concept and How to Define and Call Functions.mp4
--7.1 Self test questions
-7.2 Data Transfer in Function Call, Call Procedure and Function Return Value
--7.2 Data Transfer in Function Call, Call Procedure and Function Return Value.mp4
--7.2 Self test questions
-7.3 Declarations of called functions and nested calls to functions
--7.3 Declarations of called functions and nested calls to functions .mp4
--【Source program】Example 7.4 use a function to find the sum of t
--7.3 Self test questions
-7.4 Recursive call to function
--7.4 Recursive call to function.mp4
--【Source program】Example 7.6. How old is the fifth student?
--【Source program】Example 7.7 Use recursion method to find n!
--7.4 Self test questions
-7.5 Array as function parameter (1)
--7.5 Array as function parameter (1).mp4
--【Source program】Example 7.10
--7.5 Self test questions
-7.6 Array as function parameter (2)
--7.6 Array as function parameter (2).mp4
--【Source program】Selection sorting.
--【Source program】Example 7.13 find the maximum of a 3×4 matrix.
--7.6 Self test questions
-7.7 Local and global variables, internal and external functions
--7.7 Local and global variables, internal and external functions.mp4
--【Source program】Example 7.14
--7.7 Self test questions
-7.8 The Survival Period of Variables and the Storage Mode of Local Variables
--7.8 The Survival Period of Variables and the Storage Mode of Local Variables.mp4
--【Source program】Example 7.17
--7.8 Self test questions
-7.9 Storage Categories of Global Variables
--7.9 Storage Categories of Global Variables.mp4
--7.9 Self test questions
-Chapter 7 Self test questions
-8.1 Pointer Concept, Definition and Reference of Pointer Variables
--8.1 Pointer Concept, Definition and Reference of Pointer Variables.mp4
--8.1 Self test questions
-8.2 Pointer variables as function parameters
--8.2 Pointer variables as function parameters.mp4
--【Source program】Example 8.3. Exchange two data with function call.
--8.2 Self test questions
-8.3 Pointer of array element, operation of pointer and reference of array element by pointer
--8.3 Pointer of array element, operation of pointer and reference of array element by pointer.mp4
--【Source program】Point to array elements with pointer variables.
--8.3 Self test questions
-8.4 Using Array Name as Function Parameter
--8.4 Using Array Name as Function Parameter.mp4
--【Source program】Store array elements in reverse order.
--8.4 Self test questions
-8.5 Reference to multidimensional arrays by pointers
--8.5 Reference to multidimensional arrays by pointers.mp4
--【Source program】Pointer variable pointing to one-dimensional array.
--8.5 Self test questions
-8.6 Referencing strings through pointers
--8.6 Referencing strings through pointers.mp4
--【Source program】Reference string by pointer.
--8.6 Self test questions
-8.7 Character pointer as function parameter
--8.7 Character pointer as function parameter.mp4
--【Source program】Character pointer as function parameter.
--8.7 Self test questions
-8.8 Pointer pointing to function
--8.8 Pointer pointing to function.mp4
--【Source program】Pointer variable pointing to the function.
--8.8 Self test questions
-8.9 Functions that return pointer values
--8.9 Functions that return pointer values.mp4
--【Source program】Intercept substring.
--8.9 Self test questions
-8.10 Pointer arrays and multiple pointers
--8.10 Pointer arrays and multiple pointers.mp4
--【Source program】Sorting of strings.
--8.10 Self test questions
-8.11 Dynamic memory allocation and pointer variables pointing to it
--8.11 Dynamic memory allocation and pointer variables pointing to it.mp4
--【Source program】Dynamic memory allocation.
--8.11 Self test questions
-Chapter 8 Self test questions
-9.1 Define and use structural variables
--9.1 Define and use structural variables.mp4
--【Source program】Structure variable
--9.1 Self test questions
-9.2 Using structure arrays
--9.2 Using structure arrays.mp4
--【Source program】Structure array
--9.2 Self test questions
-9.3 Structure pointer
--【Source program】Structure pointer
--9.3 Self test questions
-Chapter 9 Self test questions
-CodeBlocks Baidu online disk download address
-Final Exam
--final exam