"C Pitfalls and pitfalls" learning notes

Source: Internet
Author: User

The nature of single quotation marks refers to a number, whereas double quotation marks essentially represent a pointer.

printf (' \ n ') is illegal in most compilers today.


Solution of A+++++b:

Such a formulation should have the most reasonable explanation:

a++ + ++b

However, the compiler performs a large-mouth compilation, and for the compiler it should at least look like this: (((a++) + +) +b), but a constant does not allow the + + operation,

So this statement becomes an illegal statement instead.


Here is a statement that tests whether a comment can be nested, returns 1 if it can be nested, or returns 0 to try.

/*/*/0*/**/1 1 0

Each type of pointer size is 8 bytes in 64-bit system size

#include <stdio.h> #include <string.h>int main () {int *a;char *b;short *c;long  *d;printf ("int=%d  char=%d short=%d long=%d\n ", sizeof (a), sizeof (b), sizeof (c), sizeof (d)); return 0;}


Arithmetic operators have the highest precedence in the binocular operator, followed by the shift operator, the relational operator again, the logical operator, the assignment operator, and finally the conditional operator.

The case of the switch statement, the bit value problem with the Dafult, and the omission of the break

F; This statement actually calculates the address of the function

Else note the matching problem with the IF

Array allowed at the end of the extra comma

The sizeof operator calculates the length of the array divided by the type and the number of array elements.

#include <stdio.h>int main () {int a[]={1,2,3,4,5,6};int b= (sizeof (a)/sizeof (int));p rintf ("%d\n", b); return 0;}


For arrays we can only do two things: Determine the length of the array, and get the element pointing to the subscript 0

Any array subscript operation is equivalent to a corresponding pointer operation.

Any pointer is a variable that points to a type

The addition of pointers is meaningless if only subtraction in the same array is meaningful

An array name is a pointer to an array that has a type that cannot be assigned to another type of pointer

A non-array pointer, a string that actually represents the word multibyte an end character in memory, is an address when using the STR series function is to make sure that the existing string is already allocated memory.

When using the malloc () function, note: 1. Determine the successful allocation, 2. Free up allocated space in time

The declaration of a pointer and an array is two completely different things

Null pointer is not an empty string

Use of the Static keyword:

1. When modifying a variable, limit the scope of the variable to the source file or local sub-function.

2. When modifying a function, limit the scope to reduce name collisions

Note The return value of the function, preferably writing the return type of the function at the time of declaration and definition, and reducing the unnecessary hassle of parameter types

Check the external type,

eg

extern int n;

Long N;

This is an invalid program, the same variable that is not restricted is declared as two different types


Generally please show the definition of the return value of the main () function

#define MAX (a) > (b) ( A):(B))

In particular, notice the type promotion of each parameter in the function call

Note that the memory location is 0

General computer does not allow to read memory address 0;

#include <stdio.h>int main () {char *p;p = null;printf ("Location 0 countion%d\n", *p); return 0;}
This program generates a segment error because it cannot access address 0.

attention to asymmetric boundary problem single citation

"C Pitfalls and pitfalls" learning notes

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.