C Language Syntax Directory one

Source: Internet
Author: User

1. #include <stdio.h>
Include is to tell the compiler that it contains a header file
In the C language, any library function call needs to include the header file in advance
< header file > representative let C language compiler go to the system directory to find the relevant header file. (System library function)
"Header file" for the C language compiler to go to the user's current directory to find the relevant header file. (Custom header file)


2. Main function
Main function is the main function of C language, a C language program has and can only have one main function.

3. Comments
Single-line Comment
/* */single-line or multiline comment

4, {} brackets
The function code is all wrapped in {}.

5. Statement
such as: int A; Declare a variable an integer variable with a name called a

6, C language custom variable requirements
Any combination of letters, numbers, and underscores
Case sensitive
You cannot use the C keyword as a variable name

7, each line end must be the English semicolon (;)

8. The printf function is the output string to the standard output device

9. Return Statement
The function terminates when it encounters a return, which is the keyword
Return a value to the calling function
return 0; The main function return 0 indicates success, 1 means failure

10, System call (call #include <stdlib.h> header file)
For example, execute: System (' calc '); The calculator program is called automatically when the compilation is executed.

11. C Language Program execution process
precompilation (. c files)--compile-to-link (executable program)
Precompiled-E (for example: A.C to A.E): Open the contents of the program header file, remove useless annotations, and so on.
Compilation:-S, converting C to C language
Compiling: Compiling code into binary machine instructions


12, the definition of constants
#define MAX=100//defines a constant MAX with a value of 100, which must be assigned the initial values and cannot be modified
const int a = 100//A is also a constant here

#define STRING "Hello"//defines a strings constant
const char *STR = "Hello C"//also defines a string constant
Description: For constants of # define type, the habit is to capitalize the constant name, but for ordinary const constants and variables, the general lowercase combination is uppercase.

13, binary number, bit, byte and word
A bit can only represent 0 or 1, two states, short bits,
A byte is 8 binary, called a 8-bit, or byte,
A word of 2 bytes, abbreviated as Word
2 words for double Word, abbreviated DWORD

14, binary, octal, hex
decimal: 0 1 2 3 4 5 6 7 8 9   Full Decimal one
binary: 0 1    full binary one
octal (O): 0 1 2 3 4 5 6 7 Ten &NBSP ; Full eight in one
Hex (0x/x): 0 1 2 3 4 5 6 7 8 9 A b c D E F   16 in one

Decimal---> octal/binary/16-binary
Decimal number as dividend, octal (binary, hexadecimal) as divisor, each time the remainder is sorted in reverse order is the octal number (binary/16-binary)
%x represents the output 16 binary number, and%x outputs 16 decimal digits in uppercase.
%o Represents the output octal number

15. sizeof keyword
The function is to specify the size, in bytes, of the data type in memory.

16, short,long,longlong,unsigned int
Short 2-byte 16bit
Long-length integer 32-bit system is 4 bytes, 64-bit system is 4 bytes, UNIX is 8 bytes
A long long is 64 bits, or 8 bytes, and the 32-bit system is inefficient
int is 4 bytes consistent (No platform)
unsigned (unsigned) 0000 0000->1111 1111 0->255
Signed 0000 0000, 1111 1111-127->127

18, Integer overflow
An integer that exceeds the maximum number of units the integer can hold will overflow, and the result of overflow is a high discard.
For example:
unsigned short a = 0xFFFF;
A = a + +;
printf ("%d\n", a);//a=99
Analysis: a = 1111 1111 1111 1111
a+100 = a+1+99 = 1 0000 0000 0000 0000 +
Short is two bytes, 16bits, more than a portion will overflow, not counted into, so:
A + 0 = + + =
when a small integer is assigned to a large integer, the sign bit is not lost and is inherited.
For example:
int i = 1234;
Short a =-2;
i = A;
printf ("%x\n", i); #? Fffffffe?

19. Big-endian alignment and small-end alignment
For the arm, Intel these x86 framework of complex instruction CPU, integer in memory is stored backwards, low address lower, high address place, is called small end alignment.
For UNIX server CPUs, more big-endian alignment is used.

As shown in the following:

20. Original code, inverse code, complement and unsigned number

1, the original code

The maximum number of digits is the sign bit (0 for positive, 1 for negative)
0000 0011-3 0011-3
2, anti-code
a number if the value is positive, then the inverse code and the same as the original code, such as: 3 anti-code 0000 0011
a number if the value is negative, then the sign bit is 1, others are opposite the original code (0 change to 0)
  
such as-3 of the anti-code is: 1111 1100
3. Complement (negative numbers in the computer are stored in the complement)
Positive Number: Original code, anti-code, and complement are the same
Negative number: The highest bit is 1, the rest of the original code to take the reverse, and finally add 1.
the conversion of negative numbers: The original code--and anti-code (except the highest bit 1 unchanged, all the rest of the negation)
Original Code <--> complement (maximum bit 1 unchanged, rest reversed, plus 1)

C Language Syntax Directory one

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.