answersLogoWhite

0

Declare 2 pointer variable of the same type and assign the address of the variable to them and then increment one of them.

Find the difference between the above 2 pointers using a type cast. This will be the size of the variable.

Eg:

double i;

double * p = &i;

double * q= p;

p++;

cout<<(int)p-(int)q<<endl;

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

JudyJudy
Simplicity is my specialty.
Chat with Judy
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
More answers

Possible, but very, very, very bad idea:

#include

#include

typedef struct test {

xtype x;

char y;

} test;

printf ("sizeof (xtype)=%d\n", (int)offsetof (test, y))

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Size of a variable without using sizeof operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp