Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to assign null value to C language
How to assign null value to C language
C language has no concept of null value. Generally speaking, the pointer to address 0 is null, and the content of other data is null. Memset function can be used to fill a large memory area, and its filling length is in bytes.

Plastic: Inta = 0;

Character type: char a = 0;;

Array:

int a[20];

memset( a,0,sizeof(int)* 20);

C string only needs to set the first character to' \0'.

Of course, it can also be completely cleared.

char a[20]= " ashdfuih ";

memset( a,0,sizeof(char)* 20);

For example, there is a structure Some x, which can be cleared like this:

memset(& amp; X, 0, sizeof (some));

If it is an array structure with some x[ 10], it can be like this:

menset( x,0,sizeof(Some)* 10);

Any pointer can be made null by directly assigning it to 0:

Some * p = 0;;