How to find size of an variable without using sizeof operator ?

Showing Answers 1 - 2 of 2 Answers

Nimmi

  • Jul 10th, 2006
 

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;

T.Raghavendra

  • Nov 23rd, 2006
 

program to find the size of variable without using sizeof operator #include main() { int i = 01; int count = 0; int size; while(i) { i = i << 1; count++; } size = count/8; printf("The size of int variable is %dn", size);

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions