<>C Language Check Chapter I C overview of the language
Computer structure :
Computer system composition :
Procedures and instructions :
* Instruction is the smallest unit of program control for a computer ;
* The set of all instructions is called the instruction system of the computer ;
* A program is a sequence of instructions written in a certain language to accomplish a specific task .
70 Early S , Bell Labs has officially published C language .
1983 Published in C Language standard ANSIC.
C Language has 32 Keywords :
Keyword classification :
9 Control statements :
34 Kinds of operators :
C Advantages of language :
* Small code size ;
* Fast execution ;
* Powerful
* Freedom of programming
shortcoming :
* Long code writing cycle ;
* Poor portability ;( Compared with assembly language ,C Good language portability )
* Too free , Inexperienced and error prone ;
* More dependence on platform library .
Process oriented concept : Analyze the steps needed to solve the problem , And then use functions to implement these steps step by step , Call one by one when using .
Object oriented concept : Decompose the constituent problem transaction into various objects , The object is not created to complete a step , It's about describing the behavior of something in the whole problem-solving process .
first C program :hello.c
#include<stdio.h> int main(void) { printf("hello,world\n"); return 0; }
stay VS Mid build run may flash by , One of the solutions :
* stay return Add before statement , system("pause");
about system function : Execute another external program in a program that is already running , I'll talk about it later .
* Other methods refer to Baidu .
stay Linux Used in the system gcc Compiler compilation
gcc -o hello hello.c
stay Windows System use gcc One of the compiler methods , install QT platform , Configure environment variables , command :
gcc -o hello.exe hello.c
#include<> and #include" " The difference between :
* < > Indicates that the system searches directly according to the directory specified by the system ;
* " " Indicates that the system first “” Specified path ( No write path represents the current path ) Find header file , If not found , Then search according to the directory specified by the system .
main The function is C The entrance of language program , The procedure is from main Function start execution ,return Represents the completion of function execution , Return return Represents the termination of a function .
int main() and void main() stay C It's the same in language , but C++ admit of only interpretation int main This way of defining .
system function :
* function : Execute another external program in a program that is already running ;
* parameter : External executable name ;
* Return value : Success : Different system return values are different , fail : Usually - 1
Example : #include <stdio.h> #include <stdlib.h> int main() { //system("calc");
//windows platform , Open calculator system("ls"); //Linux platform , View current catalog file return 0; }
system Function use needs to include header file stdlib.h
C Language all library function calls , You can only guarantee that the grammar is consistent , But there is no guarantee that the implementation results are consistent , The same library function may perform the same result under different operating systems , It could be different ,Linux Development is inseparable from
POSIX standard
, As long as the function meets this standard , The results can be consistent in different systems ,Unix and linux Many library functions are supported POSIX Of , but Windows Poor support , If Unix Code migration to Linux The general cost is very small , If Windows Code migration to Unix perhaps Linux It's more troublesome .
QT GUI call system function :
1. open QT, New project ;( Be careful :QT The project created under the platform cannot contain Chinese path );
2. Select in the open dialog box QT Graphical interface ;
3. Drag space in a new project push button Button
4. Double click button , Change button name ;
5. Right click button , Select to slot …, open a dialog box ;
6. Import system library stdlib.h input system(“calc”);
How to make runtime not pop up CMD window :
7. Import system library windows.h input WinExec(“calc”,SW_HIDE); Hide black window by default when system calls .
stay VS Creating graphical interface under the platform :(MFC) slightly
C Language compilation process :
1. Pretreatment :
1) Macro definition expansion
2) Header file expansion
3) Delete Note
4) Conditional compilation
format :gcc -E a.c -o a.i
2. Compile :
1) Check syntax
2) Convert to assembly language
format :gcc -S a.i -o a.s
3. assembly :
1) Turn assembly language into machine language
format :gcc -c a.s -o a.o
4. link :
1) Link a library file to an executable
format :gcc a.o -o a.exe
Processing by C Operation of language function warning :
#idefine _CRT_SECURE_NO_WARNINGS Put it on the first line of the program
or #pragma warning(disable:4996)
Technology
Daily Recommendation