#include<iostream> //#define size(T)(*((char*)&T+1-*(char*)&T)); #define SIZEOF(var) (size_t)(&var+1) - (size_t)(&var)
using namespace std; int main() { char a; cout<<SIZEOF(a); cin.sync(); cin.get(); return 0; } On Mon, May 31, 2010 at 1:14 PM, debajyotisarma <sarma.debajy...@gmail.com>wrote: > This is not about algorithms,but related to C programming. > > How to implement sizeof operator? > > macro for this > #define my_sizeof(a) (char*)(&a+1)-(char*)&a > > this works fine of variables > int a; > printf("%d",my_sizeof(a)); //or even for user defined > structures > > but it will not work for data types > > like > > printf("%d",my_sizeof(int)); > > so please get another solution. > function will be preferable.not macro > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.