Basic C language problems

Source: Internet
Author: User

What is the difference between "" and <> when a header file is referenced in C?

The C language compiler uses some directories to store public header files. If you use <>, you can only find the header files in the public directory. If you use "", you can first find them in the current directory, if not, find them in these directories. That is, the "" search range is large (including the <> search range), and the "" search speed is fast when the header file is in the current directory. Generally, "" should be used for custom header files, because these files are stored in the project directory (that is, the current directory of the compiler) rather than in the public header file directory, if <> is used, the header file cannot be found. The header file provided by the system, such as the header file of the library function, you can use <> "" to find all the header files, including the system library function header files and custom header files.

The length of the int type is usually 16-32768 ~ 32767 may also use 32-Bit Length

Float is a 32-bit string with at least 6 Valid numbers.

The length of the doubt type is 64-bit.

The Char length is 8


Floating Point format problems

% 3.0f characters in length make up three decimal places 0

% 6.1f occupies 6 characters, and the decimal point occupies 1

% 6f indicates 6 characters in length

%. 3f indicates that the decimal point length is 3 digits.

% D decimal

% O octal

% X hexadecimal

% S string

% Table % itself

% LD output long integer


Computing efficiency


++ I efficiency> I = I + 1;


Pointer array and array pointer

INT (* P) [10] The array pointer array stores the array P as the pointer to the array * (p + 1) = (* P) [1]

Int * P [10] The pointer array stores the pointer to the int type. P is the array.


4. Are global variables and local variables different in memory? If so, what is the difference?
Global variables are stored in the static database, and local variables are stored in the stack.

5. INT (* func) [5]) (int * P); parse

Func is enclosed by parentheses, and there is a * on the left. func is a pointer, out of parentheses, and a [] operator number on the right, which indicates that func is a pointer to an array, to the left, there is a "*" on the left, indicating that the element of this array is a pointer, and then the brackets appear on the right, indicating that the element of this array is a pointer to the function. To sum up, func is a pointer to an array. The elements of this array are function pointers. These pointers point to functions with int x parameters and return values of the int type.

What are the addresses of http://www.cppblog.com/luliang/archive/2008/09/15/61863.html? Opt = Admin


5. A rule for the value assignment expression: the left value of the value assignment expression cannot contain a qualified word!

To prevent the constant pointed to by the pointer from being modified, the c Standard specifies that the Left value must contain all the qualified words of the right value. This limits that a pointer to a const object cannot be assigned to a pointer to a non-const object, but in turn it is allowed. This provision seems very reasonable at the beginning, but its utility is actually only limited to the first-level pointer. The assignment between second-level pointers is no longer safe even if it meets the requirements.


6. | & ^> <Operator

1. bitwise and operation bitwise AND operator "&" are binary operators. Its function is the binary phase corresponding to the two numbers involved in the operation. The result bit is 1 only when the two binary numbers are 1. Otherwise, the result bit is 0. The number of involved operations is supplemented.
For example, 9 & 5 can be written as follows: 00001001 (Binary complement of 9) & 00000101 (Binary complement of 5) 00000001 (Binary complement of 1) Visible 9 & 5 = 1.
Bitwise AND operations are usually used to clear some bits or retain some bits. For example, if a clears the high eight bits of 0 and retains the low eight bits, it can be used as a & 255 operation (255 of the binary number is 0000000011111111 ).

2. bitwise OR operator "|" is a binary operator. Its function is the binary phase or corresponding to the two numbers involved in the operation. If one of the two binary numbers is 1, The result bit is 1. The two numbers involved in the operation appear as a complement.
Example: 9 | 5 writable formula: 00001001 | 00000101
00001101 (decimal 13) Visible 9 | 5 = 13
 
3. bitwise exclusive or operation bitwise exclusive OR operator "^" is a binary operator. This function is used to calculate whether the binary numbers corresponding to the binary numbers are different or not. When the binary numbers of the two numbers are different, the result is 1. The number of involved operations still appears as a complement Code. For example, 9 ^ 5 can be written as follows: 00001001 ^ 00000101 00001100 (12 in decimal format ).

0 ^ 0 = 0, 1 ^ 0 = 1, 0 ^ 1 = 1, 1 ^ 1 = 0

0 ^ 0 = 0 0 ^ 1 = 1 0 variance or any number = any number

1 ^ 0 = ^ 1 = 0 1 variance or any number-returns the inverse of any number

Set yourself to 0 for any number difference or yourself =

(2) bitwise exclusive or operation can exchange two values without using temporary variables. For example, you can use the following statement to exchange the values of two integers, A and B:
A = 10100001, B = 00000110
A = a ^ B; // A = 10100111
B = B ^ A; // B = 10100001
A = a ^ B; // A = 00000110

------ If your notes are incorrect, please pick them up. Thank you.

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.