sizeof operator

In programming language like C,C++ the sizeof operator generates the sizeof its operand. Operand may be any data type or constants. It gives the sizeof datatype or constants in bytes.

syntax of sizeof operator:


  • If you have to find out the size of any datatype you must have to use first syntax. Your datatype must be within the small brackets sign, if you will use second syntax it will show you error.
  • Second syntax can be used while finding out the size of constants like 4,6,9.8 etc.
  • The keyword sizeof must be a single word. Size and of must not separated otherwise it will show you error.

Let us have a look to program given below, you will be more clear about sizeof operator .




all the above size are in bytes.

Why sizeof operator?:

  •  Generally while doing any program or writing sizeof operator in any program a question might have came in your mind the datatype which you are using for storing your data will be sufficient or not whether you should go for another type of datatype or you should continue with the same datatype. So you need not to be worry about this kind of questions. Reason behind this is that sizeof operator helps us to overcome this type of questions. By using sizeof operator you can find out how much memory your data will consume and you can use different type of datatype as you required.
  • It is useful in allocating the memory as required by the user .In C function like malloc(),calloc() and realloc() are used to allocate memory.In these function sizeof operator is used. More about calloc(),malloc() and realloc() will be discussed later as required.
  • There are many site which provides information related to the Programming please click here for more details.


Leave a Reply