answersLogoWhite

0


Best Answer

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

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

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))

This answer is:
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
Related questions

In pointers what is the use of pointer variable?

Pointer is a variable that stores the address of another variable . So pointer basically stores the address of another variable and size of pointer can be evaluated by using sizeof operator.


Can array size be determined using sizeof operator in c?

Yes. The array name is a reference to the array, so you can use sizeof (name) / sizeof (name[0]) to determine the number of elements. Note that sizeof (name) alone gives the length of the array in bytes.


How do you find the greatest of three numbers using ternery operator?

Compare the first two numbers with the ternary operator. Store the result in a temporary variable. Compare the temporary variable with the third number, again using the ternary operator.


How do you define power function without using operator?

using pow() function.. ..


Get size of int using sizeoff?

printf ("sizeof (int) = %d\n", (int)sizeof (int));


Can you increment the value of a variable by 2 using any increment operator?

There is no such increment operator in C language to increment the value of a variable by 2.An increment operator only increments the value by 1. however you can apply the increment operator twice to get an increment of 3. No: you cannot: ++(++a) won't compile. Yes. Example: a += 2; but += is not an increment operator, it's a shorthand of a=a+2; just like a++ is a shorthand for a= a+1


Swap logic without using third variable?

a ^= b; b ^= a; a ^= b;


How do you write find out the power of a number without using operator and predefined functions?

With repeated multiplication.


How can an individual structure member be accessed in terms of its corresponding pointer variable?

By dereferencing the pointer variable. This can be achieved in two ways: typedef struct s { int i; float f; }; void f (struct s* p) { int x = p-&gt;i; /* using pointer to member operator */ float y = (*p).f; /* using dereference operator */ } The two methods are functionally equivalent.


Can you assign value to variable without using picture clause in mainframes?

No. In COBOL, any variable must be declared with PIC statement.


What is the advantage of swapping two variables without using 3 variable?

Nothing. Never do that.


How do you declare an N-Dimensional array using Malloc?

#include &lt;stdlib.h&gt; int **array1 = malloc(nrows * sizeof(int *)); for(i = 0; i &lt; nrows; i++) array1[i] = malloc(ncolumns * sizeof(int));