filmov
tv
Print the size of int without using sizeof operator | Interview question

Показать описание
In this instead of using sizeof operator, I have used the concept of pointer in order to represent the size of integer datatype.
For representing the size of integer, I firstly took an integer pointer
and initialized it with zero.In the second instruction I incremented the pointer by one. But since a pointer is a special variable which stores the address of the variable therefore IT DOESN'T INCREMENTS SIMPLY BY ONE BUT INCREMENTS ITSELF BY THE SIZE OF DATA TYPE TO WHICH IT BELONGS. Since initially pointer consisted of zero therefore in next instruction it incremented 0 to 4 i.e the size of integer.
you can also follow my tutorials on unacademy
For representing the size of integer, I firstly took an integer pointer
and initialized it with zero.In the second instruction I incremented the pointer by one. But since a pointer is a special variable which stores the address of the variable therefore IT DOESN'T INCREMENTS SIMPLY BY ONE BUT INCREMENTS ITSELF BY THE SIZE OF DATA TYPE TO WHICH IT BELONGS. Since initially pointer consisted of zero therefore in next instruction it incremented 0 to 4 i.e the size of integer.
you can also follow my tutorials on unacademy