Header Ads Widget

Compile time operator sizeof

sizeof is unary operator that returns the size of its operands in bytes. Operand can be a variable, constant or any data type. sizeof primarily helps to generate portable code that depends upon the size of built -in data types.  sizeof is evaluated at compile time, and the value produced by this operator is treated as constant within that program.

#include <stdio.h>

int main( )

{

  int x, y;

  float z;

  printf("\n Size of int = %d"sizeof(int));

  printf("\n Size of x = %d"sizeof(x));

  printf("\n Size of float= %d"sizeof(float));

  y=sizeof(z);

  printf("\n Size of z = %d", y);

  return 0;

}

sizeof is implemented as an operator in C. sizeof can take type as an argument. In general, sizeof is compile time operator but when it is applied to a variable length array, sizeof is evaluated at run time because size of variable length array can not be known until run time.

Post a Comment

0 Comments