The basic grammar and principles of C language are initially:

Source: Internet
Author: User

The basic grammar and principles of C language are initially:

/* ******************************************* *

Data type

Description Data size

Char 1

Short 2

int 4

Float 4

Double 8

Constructed type

Storage type

The location that is stored in memory

(Heap, stack (auto), static region, code snippet)

Function

Operation of the code (what to Do)

+-*/% & | | is an operator

Control statements

Select or cycle

Function

* ******************************************** */

Identifier

Variable:

1. Numbers, letters, underscores

2. The first letter is not numeric and case-sensitive

3. Not the same as system keywords

To define the format of a variable:

< storage type > < data type > < variable name >

|           | | An alias for the application space

| | Explain the size of the application space

| char Short int

|

Describes the location of the requested space in memory.

Auto static extern Register

stack static static registers

int a = 998; Initialization

int b; Define First

b = 998; Post-Assignment value

Constant:

Direct constants:

int a = 5;

float F = 3.14159;

"Hello World";

char c = ' A ';

Symbolic constants

#define PI 3.14159

int a = 6;

int const A = 6;

const int a = 6;

Const represents a constant quantization and cannot be changed by assigning a value to a space

Storage Base Unit:

Bit bits

Bytes Byte KB MB GB

How the data is represented:

1. Integers:

Integral type data:

Decimal

Octal < can only represent integers (char short int long) >

Hexadecimal < can only represent integers (char short int long) >

Binary (c language is not supported, but only binary is recognized inside the computer)

Binary conversions:

Decimal <==> Binary

integer-to-binary divide, except 2 for remainder, read from bottom up

Decimal---binary multiply by 2 rounding, from top to bottom

Binary ==> octal

Signed and unsigned integer data:

signed int x; (symbol type highest bit as symbol 0 for positive number, 1 for negative number)

unsigned int y; (highest bit also as valid data bit)

Printing of integral type:

Signed type;

printf ("%d", x);

Unsigned type:

printf ("%u", y);

2. Characters:

ASCII code:

Original code:

directly to binary, the most primitive binary representation method, but in the case of a negative number operation, the result is wrong. Then the inverse code is proposed.

Anti-code:

The inverse code of positive numbers is the same as the original code, and the inverse of negative numbers is reversed on the basis of the original code (the sign bit is invariant).  The inverse code solves the problem that the original code cannot be calculated, but at the same time brings 0, and then puts forward the complement. (The inverse Code addition uses the method of cyclic carry)

Complement:

Positive complement and inverse code are the same

The complement of negative numbers is based on the inverse code +1. (except for the original counter +1, the sign bit)

Range of values:

Signed type characters:-128 ~ 127

Unsigned type character: 0 ~ 255

Ps:

The maximum value of type +1--to the minimum value of the type

The minimum value of type -1--to the maximum value of the type

3. Real type/floating point type:

Single Precision Float

1 bit sign bit + 8 bit exponent bit +23 decimal place (offset code +127)

To store a floating-point data in memory:

1. Convert floating-point data into binary exponential form, get symbol bit exponent data size

2.float memory The highest bit holds the symbol bit, followed by 8 bits to hold the index +127 of the binary, low 23 bits of the data stored in the decimal place, yes, the whole number of data is discarded directly (because the integer digits of the binary data must be 1, so can be omitted, the restoration is added on the line)

Demonstrate:

6.9 Saving in memory

Test: Store 17.625 in memory

Double-precision Doubles

1 bit sign bit + 11 bit exponent bit + 52 decimal place (offset code +1023)

Accuracy range guarantees 15-bit valid data

Determine if a float type variable x is 0:

#define EP 0.000001

if ((X<=EP) && (X>=-EP))

{

}

The basic grammar and principles of C language are initially:

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.