002-c Language Overview

Source: Internet
Author: User

C language

Key words:

32 keywords, all lowercase

  Auto double int struct break else long switch

Case enum Register typedef char extern return Union

const float Short unsigned continue for signed void

Default goto sizeof volatile do if and static

Identifier

Customize some of the symbols and names. cannot be duplicate with keyword.

Naming rules

1, Composition: 26 English letters, 10 digital 0~9, Underline _

2. Strictly case-sensitive

3. Cannot start with a number

4. Keywords cannot be used as identifiers

Comments

Explain the meaning of a line of code. The position is not fixed. But it's best to put a line in the code or behind the bank. The comment code does not participate in compilation.

Single-line Comment://single-line comment

Multi-line Comment:/* Multiline Comment

Multi-line Comment */

Data

static data and Dynamic Data

Static data: In the hard disk, and the computer to open the machine Independent

Dynamic Data: In memory, all data is lost after the computer shuts down

Data type

1> Constants

Integer constant (1,3445), floating-point constant (double,float) character constant (' a ', ' B '), string constant ("Asdfadsfas")

2> variable

The amount of time that has been changed during use can be represented by a variable

Definition mode: Variable type variable name ;

int score;//Definition
Score = 100;//Assignment

scanf function to get user input

int age;
scanf ("%d", &age);

  The scanf function waits for the user's keyboard input and does not execute the code backwards. The 1th parameter of scanf is "%d", stating that the user is required to enter an integer in 10 binary form. Note here that the2nd argument of scanf is not the age variable, but the addressof the age variable &age,& is an address operator in C that can be used to get the address of the variable .

printf function , output data

printf ("%d", age);

The function prototype is extern void printf (const char *format,...); Multiple parameters can be accepted.

For example

1     int i, j;2     scanf ("%d,%d", &i, &j), 3     printf ("i=%d;j=%d", I, j);//multiple parameters, output multiple values

Scope of the variable

Start with the defined sentence until the end of the code block.

A code block is all the code inside a curly brace. The scope of a variable defined inside a code block is inside that code block.

1 int Main ()
2 {
3 int score = 100;
4 {
5 int score = 200;
6
7 }

9}

Local variables (variables defined inside the function) and global variables (variables defined outside the function)

Local variables inside the function override global variables.

Memory address

Memory address is contiguous, in bytes

Char 1;int 4;float 4;double 8

Variable memory address allocation, memory addressing from large to small, so the first defined address value is larger.

int a=10;

printf ("A's address is:%p", &a),//%p used to output address,& used to take the variable address

To be Continued ...

002-c Language Overview

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.