Let us assume I have declared the variable \'i\' of certain datatype (might be int, char, float or double) ...
NOTE: Simply consider that \'i\' is
This should give you the size of your variable
#define mySizeof(type) ((uint)((type *)0+1))
I hope that below code would solve your problem in c++ without using sizeof() operator
for any variables like (int, char, float, double, char, short and many more...)
here I take integer,
int a;
then show it as byte addressable output,
cout<<(char *)(&a + 1) - (char *)(&a);
Program to find Size of the variable without using sizeof
operator
#include<stdio.h>
int main()
{
int *p,*q;
int no;
p=&no;
printf("Address at p=%u\n",p);
q=((&no)+1);
printf("Address at q=%u\n",q);
printf("Size of int 'no': %d Bytes\n",(int)q-(int)p);
char *cp,*cq;
char ch;
cp=&ch;
printf("\nAddress at cp=%u\n",cp);
cq=cp+1;
printf("Address at cq=%u\n",cq);
printf("Size of Char=%u Byte\n",(int)cq-(int)cp);
float *fp,*fq;
float f;
fp=&f;
printf("\nAddress at fp=%u\n",fp);
fq=fp+1;
printf("Address at fq=%u\n",fq);
printf("Size of Float=%u Bytes\n",(int)fq-(int)fp);
return 0;
}
#include<stdio.h>
#include<conio.h>
struct size1
{
int a;
char b;
float c;
};
void main()
{
struct size1 *sptr=0; //declared one pointer to struct and initialise it to zero//
sptr++;
printf("size:%d\n",*sptr);
getch();
}