Sizeof() Operator

  • Sizeof() Operator is useful for finding the size of a variable or finding the size of the datatype.
  • The unary operator only needs 1 operand to perform a task.

Example :

  1. main()

{

int i = 10;

printf(“%d %d %d”,sizeof(int),sizeof(i),sizeof(10));

}

 

Answer: 4  4  4

2. main()

{

int i = 10;

printf(“%d %d %d”,sizeof(int),sizeof(char),sizeof(‘a’));

}

Answer: 4 1 1

Sizeof() operator always gives decimal output.

Sizeof operator will not solve any expression.

Example:

main()

{

int i = 10;

printf(“%d %d %d”,sizeof(++i));

}

Answer: 4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: