stddef.h in C
The file header named stddef.h in C Library defines various types of variables and macros. Many of these definitions are also present in other headers.
The variables are defined in stddef.h
The following lists some types of variables defined in stddef.h in Library C:
Description variable ptrdiff_tThis is a signed integer type and is the result of subtraction of two pointers
size_tThis is an unsigned integer type and the result of the sizeof keyword
wchar_tThis is an integer type, the size of a large character constant (wide char)
Macros are defined in stddef.h
The table below lists some macros defined in stddef.h in Library C:
Macro Description NULLThis macro is the value of a null pointer constant
offsetof (type, member-designator)These results are in an integer constant of type size_t which is the offset (byte unit) of a structure member from the beginning of that structure. Members are provided by the member-designator parameter, and the name of the structure provided by type
1. Macro NULL () in C
The NULL macro in Library C is the value of a null pointer constant. It can be defined as ((void *) 0), 0 or 0L depending on the Compiler.
Macro declaration NULL () in C
The following may be the declaration for NULL Macro depending on the compiler.
#define NULL (( char *) 0 ) ho ặ c #define NULL 0L ho ặ c #define NULL 0
Parameters
This macro does not receive any parameters
Returns the value
This macro does not return any values
For example
The following C program illustrates how to use NULL Macro.
#include #include int main () { FILE * fp ; fp = fopen ( "nofile.txt" , "r" ); if ( fp == NULL ) { printf ( "Khong the mo nofile.txt !!!n" ); } return ( 0 ); }
Assuming we want to open a non-existent nofile.txt, when compiling and running the above C program will result:
2. The offsetof macro () in C
The offsetof (type, member-designator) macro in standard C Library results in an integer constant of type size_t which is the offset (byte unit) of a structure member from the beginning of that structure. Members are provided by member-designator, and the name of the structure provided by type.
Offof () Macro declaration in C
Below is the declaration for offsetof () Macro.
offsetof ( type , member - designator )
Parameters
type - This is the type of class where member-designator is a valid identifier.
member-designator - This is the member name of the class type.
Returns the value
This macro returns the value of type size_t which is the member offset in the type.
For example
The following C program illustrates the use of offsetof () Macro.
#include #include struct student { char name [ 50 ]; char school [ 50 ]; int rollno ; }; int main () { printf ( "name offset = %d byte trong student struct.n" , offsetof ( struct student , name )); printf ( "class offset = %d byte trong student struct.n" , offsetof ( struct student , school )); printf ( "rollno offset = %d byte trong student struct.n" , offsetof ( struct student , rollno )); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Last lesson: stdarg.h in C
Next lesson: stdio.h in C
You should read it
- How to turn on / off Macro in Word
- string.h in C
- How to disable Macro mode and auto-switch on iPhone camera
- setjmp.h in C
- How to Add a Button to a Macro
- How to troubleshoot macros in Excel not working
- errno.h in C
- How to Remove a Macro in Excel
- assert.h in C
- How to Create an OpenOffice Macro
- stdarg.h in C
- The class of macro camera of the Galaxy A51 is what users rarely see
Maybe you are interested
The surprising truth is that many Gen Zers don't know how to type with 10 fingers.
If you're not already using this type of keyboard, it's time to switch!
This WhatsApp feature saves you from having to retype messages
Don't build a smart house without these 4 types of devices!
This is the type of password that takes 34,000 years to crack
What type of smartphone camera grid is best?