Size of Operator in C

C: Size of Operator

Size of operator are used to determine the size,in bytes, of a variable or data type.It is a keyword but it  is also a compile time operator.
SizeofOperator in C

Size of Operator

Size of operator are used to determine the size,in bytes, of a variable or data type.It is a keyword but it  is also a compile time operator.

The size of operator helps in memory allocation for data structures that are passed out of managed application to unmanaged code like Interop, custom serialization, etc.

The symbol or we can say syntax of Size of operator is-

Sizeof (data type)

The size of operator can be used to get size of data type ,classes ,structure and any other user defined data type.

Implementation of Size of operator

  • We know that actually work of Size of operator so we implement size of operator in this program.
  • When we initialize the data type like int,char,float,double so in this data type have some value in bytes.
  • like int has 2 bytes space in memory so in this program we find the value of some data type in bytes.

Code for Size of Operator in C

Run
#include <stdio.h>

int main()
{
int a,x;
char b;
double c;
float d;
x= sizeof(a);

printf("\n%d",x);
printf("\n%d",sizeof(b));
printf("\n%d",sizeof(c));
printf("\n%d",sizeof(d));

return 0;
}

Output

4
1
8
4

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription