sizeof() operator is a unary operator used to find the size of the arrays or the size of a variable or size of structures in terms of bytes. If we use sizeof(variable), it returns the size taken by it in terms of bytes.
Syntax:
Example:
This program returns the output as
Syntax:
sizeof(variable_name);Let us the application of the sizeof operator in the following example.
Example:
- #include<stdio.h>
- main()
- {
- int a=3;
- int b[2];
- printf("%d\n",sizeof(a));
- printf("%d\n",sizeof(b));
- return 0;
- }
This program returns the output as
- 2
- 4
This is because, the variable a is of int type, hence it takes 2 bytes.
And the array b is of int type and the array size is 2. Hence it takes 4 bytes.