sizeof Operator

What is sizeof operator?

sizeof will return the number of bytes reserved for a variable or data type. The sizeof operator is a compile-time operator that returns an integer value. In other words since sizeof is a compile time operator, when used in a expression, it does not get compiled into executable code in the expression.

Syntax of this operator is

sizeof (type-name)

For instance if one wants to know the length of a data type it can be obtained by using sizeof operator as follows:

main()
{
printf("%d n", sizeof(int));
}

This returns the size of integer which is generally 2.

Suppose we have a program like below

main()
{
int a;
float b=4.0
a= sizeof(10) / sizeof(b);
)

Then the result would be sizeof integer value generally would be 2 and sizeof float which would be generally 4. Therefore result would be 2/4 which gives result as 0.

Editorial Team at Geekinterview is a team of HR and Career Advice members led by Chandra Vennapoosa.

Editorial Team – who has written posts on Online Learning.


Pin It