C pointer principle (68)-C Quick Start (1)

Source: Internet
Author: User

I. Introduction to C

1. Introduction to C Language

All contents of the good AI Park blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/

C language is a simplified syntax language with only 32 keywords. C language uses the main function as the main function. After the program is compiled and run, the main function is executed. Therefore, A lot of c language programs have formed an interesting landscape: header files and many c code files are constructed with the main function as the center and starting point, and the code written in these files is called in the main function, reference header files. C language programs call functions provided by the C standard library, functions provided by other C libraries, API interfaces provided by the operating system, and self-defined functions, at the same time, appropriate data structures and algorithms are used to complete the work.

C language is concise but powerful. It can not only do things that are more complex than it, but also do jobs that are not good at other languages, such as operating systems, LINUX and UNIX kernels, gnome desktops, and so on are all masterpiece of C language. Especially in the design and development of system kernels, its "Brother" C ++ is not an opponent (so far, there is no kernel for a desktop or embedded system created in C ++ ).

2. Keywords in C Language

Auto: Declares automatic variables.
Short: declare short integer variables or functions
Int: Declares integer variables or functions.
Long: declares a long integer variable or function.
Float: Declares floating point variables or functions.
Double: Declares double-precision variables or functions.
Char: declare struct variables or functions
Struct: Declares struct variables or functions.
Union: Declares the shared data type.
Enum: Declares the enumeration type.
Typedef: Used to get an alias for the Data Type
Const: declare Read-Only variables
Unsigned: Declares unsigned type variables or functions.
Signed: Declares signed variables or functions.
Extern: declared variables are declared in other files
Register: Declares register variables.
Static: declare static variables
Volatile: indicates that variables can be implicitly changed during program execution.
Void: declares that a function has no return value or no parameter and has no type pointer.
If: Condition Statement
Else: The Condition Statement denies the branch (used with if)
Switch: used for switch statement case: switch statement Branch
For: a loop statement.
Do: the body of the loop statement.
While: the loop condition of the loop statement
Goto: unconditional jump statement
Continue: ends the current cycle and starts the next cycle.
Break: jump out of the current loop
Default: "other" branch in the switch statement
Sizeof: calculates the length of the data type.
Return: the loop condition of the subprogram return Statement (which can contain parameters or parameters ).

Guess Number:

Let's build a game that guesses numbers step by step.

The general idea of the game is: enter a positive integer between 1 and. Based on the Number entered by the player, the program prompts that the number is larger than before the correct answer, or the number is smaller than the correct answer, for example, if the number to be guessed is 85, the player enters 90 for the first time, indicating that the number to be guessed is larger than the number to be guessed. If the number to be guessed is 80 for the second time, the number to be guessed is smaller than the number to be guessed, the system prompts you to guess.

Next we will build this game step by step to help you quickly review the basic knowledge of C language.

(1) Compile and execute the code for inputting numbers.

Dp @ dp :~ /Cquick % cat guessnum. c

# Include

Int main (){

Int mynum;

Printf ("hello, please enter a number :");

Scanf ("% d", & mynum );

Printf ("\ n the number you entered is: % d \ n", mynum );

}

Then compile and execute on the terminal:

Dp @ dp :~ /Cquick % gcc guessnum. c-o myguess

Dp @ dp :~ /Cquick %./myguess

Hello, please enter a number: 55


The number you entered is: 55

All contents of the good AI Park blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/

Dp @ dp :~ /Cquick %

Looking at the above program and its execution results, we can find that the printf function can be used in the C language to output the screen. The scanf function can be used to input data in the specified format. In addition, "\ n" indicates a line break, "% d" indicates the integer format.

(2) restrict the range of input numbers

The requirement for a game is an integer between 1 and.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.