c interview questions - Write macro to get the size of a variable , without using sizeof() #shorts

preview_player
Показать описание
c interview questions - Write macro to get the size of any variable , without using sizeof() API

This is a tricky question, commonly asked question in c interviews.
Write MACRO , for getting the size of a variable, without using size of API.

I request you to think , and put your answer in comment , before procedding.

It is very simple, think from pointer concept. When we increment an integer pointer by 1, address increments by 4. For short , address increments by 2. For character , address increments by 1.

We can get size of any variable , by subtracting the addresses , for pointer plus 1 , and current pointer.

#pointers #cprogramming #shorts #bydubebox
Рекомендации по теме
Комментарии
Автор

What if we want to type of int using macro

nvenkatesh
visit shbcf.ru