The use and unpopular knowledge of "feeling weird" in C language


Cold knowledge (detailed reasons are in the blog post of "Basic _C Various Tables" <_<)


[int max()] Parentheses [()] are called "function call operator " here, see Tan Haoqiang C Fourth Edition P57.

[(int *)a] Convert the variable a to int* type, (type) is the cast operator (https://zhidao.baidu.com/question/124605416.html)

Operations between variables of different types: lower precision will be automatically converted to higher precision

Why is the difference between lowercase a (97) and uppercase A (65) 32 instead of 24? Just the 1 in the third place from the left :
The binary of a (97): 01 1 0 0001 ; the binary of A (65): 01 0 0 0001 ; (hardware is easy to change)


Common quirky usage


int*&a 

Meaning: a reference to an integer pointer a


* pointer 

Associativity: Right to Left

Write it down as: an operation like "multiplying" a variable name by a type?


Priority: lower than [.]
r -> and(*r).
r-> This is exactly equivalent to (*r). , but saves two characters.

strcpy((*r).name,"Leigh");

You can treat *r like a normal struct variable , but be careful with C 's operator precedence issues. If the parentheses around *r are removed, the code will not compile because the "." operator takes precedence over the "*" operator . The constant typing of parentheses when working with struct pointers is tiresome, so C introduced a shorthand for the same purpose:

strcpy(r->name,"Leigh")



pointer in project

static
void* (from http://zhengdl126.iteye.com/blog/1739165)

  The real role of void is:
  (1) Limitation of function returns;
  (2) Limitation of function parameters.

  We will elaborate on the above two points in Section III.

  As we all know, if the pointers p1 and p2 are of the same type, then we can directly assign each other between p1 and p2; if p1 and p2 point to different data types, we must use the

cast operator to convert the pointer on the right side of the assignment operator. is the type of the left pointer.

  For example:
float *p1;
int *p2;
p1 = p2;

  where the p1 = p2 statement will compile an error, prompting "'=' : cannot convert from 'int *' to 'float *'", must be changed to:
p1 = ( float *)p2;
and void * is different, any type of pointer can be directly assigned to it without casting:
void *p1;
int *p2;
p1 = p2;
  But this does not mean that void * also Pointers of other types can be assigned without casting. Because "untyped" can contain "typed", and "typed" cannot contain "untyped". The reason is very simple, we can say "men and women are people", but not "people are men" or "people are women". The following statement compiles with an error: void *p1; int *p2; p2 = p1;   prompts "'=' : cannot convert from 'void *' to 'int *'". 








 
static void * a = &a; //以上两种的组合(以下摘自https://zhidao.baidu.com/question/422255015.html)

void*()()//void型函数指针

void * fun( ) ; //声明一个返回值是任意类型的指针  的函数fun()void vfun( ) ; //声明一个没有返回值      的函数vfun()

void (*)( )  这是一种变量类型,可用来定义函数指针变量,如:

void (*pfun)( ) ; //声明一个函数指针变量pfun,该类型函数就是void vfun( ) 这种类型,pfun可以指向这类函数,如:pfun=vfun ;


结构体的指针*L

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325938107&siteId=291194637