C and Pointers

Source: Internet
Author: User

I. Get started quickly

1. Logically Delete a program:

#if 0

Statements

#endif

2. printf function:%d decimal integer value,%o octal,%x 16,%g floating-point value,%c character,%s string

scanf function:%d integer value,%ld Long integer,%f floating point,%lf double,%c character,%s string

3. Char *strchr (char* dest, char src) = = Returns the position of the first occurrence of the SRC character in the dest string

Char *strstr (char* dest, char* src) = = Returns the position of the first occurrence of the SRC string in the dest string

Two. Basic concepts

1. cc-c test.c main.c The source file test.c, main.c compile to generate the target file test.o and MAIN.O; cc TEST.O MAIN.O link several target files

2. int ch; while ((ch = getchar ())! = EOF) {putchar (ch)};

Three. Data

1. You can assign a string constant to a pointer to a character, but you cannot assign a string constant to a character array, because the direct value of a string constant is a pointer, not the character itself.

2. Char *message = "Hello World";(to declare a message as a pointer to a character, and initialize it with the address of the first character in the string constant as its value) equivalent to char *message; message = "Hello World";

3. typedef appears in the definition in front of Char *ptr_to_char; typedef char *PTR_TO_CHAR; Ptr_to_char A; Declares a as a pointer to a character

Four. Statements

1. while (scanf ("%f", &value) = = 1 && value >= 0) {}

2. switch (expression) {case constant-expression:}//expression result must be an integer value, constant-expression must be a constant expression

3. switch (CH)

{

Case ' \ n ': line + = 1;

/* FALL THRU */fall through indicates that CH runs through all the case, and when \ n is satisfied except for line+=1, the words+=1 and chars+=1 below will execute

Case ':

Case ' \b ': words + = 1;

/* FALL THRU */

Default:chars +=1;

}

4. C does not have a Boolean type, use an integer expression instead of

5. C does not have any I/O input/output statements, and C does not have any exception handling statements, which are implemented by calling library functions.

Five. Operators and expressions

1. Place the specified number of digits 1:value |= (1 << bit_number), place the specified number of digits 0:value &= (~ (1 << bit_number)), and determine if the specified number of digits is 0:value &= (1 < ;< bit_value)

2. The value of the comma expression is the rightmost value of the entire expression. if (b-10, c+4, d>0)//executes from left to right, but the value of the entire expression is d>0

3. Subscript reference: array[subscript] equivalent to * (array + (subscript))

4. Lexp represents the left value, the left value represents a position, Rexp represents the right value, the right value represents a value, the right value is not used where the left value is, and the left value can be used where the right value

5. Uppercase to lowercase: #include <ctype.h> tolower (CH);

Six. Pointers

1. The hardware accesses the memory location through the address, and the compiler helps us to access the memory location through the variable.

2. The type of the value is not an attribute inherent in the value itself, but depends on how it is used

3. The value of the variable is the value stored in the memory location assigned to the variable, even if the pointer variable is not the exception

4. Paragraph violation: segmentation violation; Memory Error: Memories fault

5. Find a specific worthwhile function in a specific array: The Return status value indicates whether it is found, if found, and then returns a pointer to the

6. Before dereferencing or indirectly accessing a pointer, you must ensure that the pointer is not a NULL pointer

7. * (int *) 100 = 25; casts an integral type to a pointer to an integral type for access to the device controller interface

8. *p+1 indicates that the *p value plus 1;* (p+1) indicates that P points to the address plus 1 after the value

9. Char Ch;char *CP = &ch; The *cp++//①++ operator generates a copy of the CP ②++ operator and adds the value of the CP ③ finally performs an indirect access operation on the CP copy.

When the expression *cp++ as the left value, the memory position of CH is represented as the value of CH when the right value

2.431 109

C and Pointers

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.