Analysis of special knowledge points in C language

Source: Internet
Author: User

1 Array 1.1 Concepts

An array is a type of data that is stored sequentially in memory. The brackets ([]) are the identifiers of the arrays, and the values inside the brackets identify the number of variables of that data type, and the brackets also take the value .

1.2 Array use

int a[10]={1,2,3,4,5,6,7,8,9,0}; --Definition of the array
int *p=&a[1]; --a[1], is the value of array A in memory 1 position, &a[1], is the address of a[1]

P[6] is equal to 8--p[6], which is the starting position of &a[1], and the value of the sixth position is taken up.

1.3 Integer Array zeroing 1.3.1 Bzero ()

can only clear zero.

1.3.2 memset ()

Can be set to the specified value. However, only the low of each byte is placed to the specified value. For example:

int a[5] = {1,2,3,4,5};
memset (A,2,sizeof (a));
for (int i=0; i<5; i++) {
printf ("%d", a[i]); --The printed value is: 10000000100000001000000010
}

2 Storage class Keywords 2.1 auto

Used only in variable declarations with code block scope, decorated with local variables.

2.2 Register

Can only be a local variable and is a type acceptable to the CPU and cannot be accessed. Can greatly improve the computational efficiency.

2.3 Static

(1) static modifier global variable, initialized only once, to prevent the use of other files.

(2) Static modifies the local variable, and the static variable is not freed when the function is executed.

(3) static modifier function, which can only be used in this file.

2.4 extern

Declares that a variable or function can be called externally.

2.5 Const3 The operation of symbolic shaping and unsigned shaping

int main (void)
{
unsigned int a = 6;
int b =-20;
char c;
(a+b>6)? (c=1):(c=0);

return 0;
} is c=1, but a+b=-14; If a is of type int then c=0.

When the original signed number and unsigned number are compared (==,<,>,<=,>=), the signed number is implicitly converted to an unsigned number (that is, the underlying complement does not change, but this number is changed from the signed number to the unsigned number),
For example above (A+B) >6 This comparison operation, A+B=-14,-14 's complement is 1111111111110010. when this number is compared, it is treated as an unsigned number , which is far greater than 6, so the result is obtained.

4 original code, anti-code, complement

Because the true value of the original code of the symbol is inaccurate, there is an inverse code, because 0 this special value, so the appearance of the complement. So, the processor calculates the complement.

  

Analysis of special knowledge points in C language

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.