C sizeof Operator: Complete Guide

The sizeof function in C language is an operator that returns the size of a data type in bytes. Its syntax is as follows:

sizeof(data_type)

The data_type can be any valid data type, such as primitive data types, structures, pointers, etc. For example, if you want to get the size of an int type, you can write it like this:

int size = sizeof(int);

Additionally, the sizeof function can also be used to obtain the size of an array, for example:

int arr[] = {1, 2, 3, 4, 5};
int size = sizeof(arr) / sizeof(arr[0]);

This will give you the number of elements in the array.

It’s important to note that the sizeof function is calculated at compile time, so the code doesn’t actually run to determine the size, which helps avoid some runtime overhead.

bannerAds