how to find the size of the data type like int,float
without using the sizeof operator?
Answer Posted / abdur rab
#include <stdio.h>
struct node {
int x;
int y;
};
unsigned int find_size ( void* p1, void* p2 )
{
return ( p2 - p1 );
}
int main ( int argc, char* argv [] )
{
struct node data_node;
int x = 0;
printf ( "\n The size :%d",
find_size ( (void*) &data_node,
(void*) ( &data_node +
1 ) ) );
printf ( "\n The size :%d", find_size ( (void*) &x,
(void*) ( &x + 1 ) ) );
}
It will work for any data type
| Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
Define the scope of static variables.
Why & is used in c?
Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc...xyz in s2 . Allow for letters of either case and digits, and be prepared to handle cases like a-b-c and a-z0-9 and -a-z. z-a:zyx......ba -1-6-:-123456- 1-9-1:123456789987654321 a-R-L:a-R...L a-b-c:abbc
How can I call fortran?
What is the difference between char array and char pointer?
What will be the outcome of the following conditional statement if the value of variable s is 10?
What is the return type of sizeof?
What happens if you free a pointer twice?
Is malloc memset faster than calloc?
Where can I get an ansi-compatible lint?
Is it better to use a macro or a function?
If null and 0 are equivalent as null pointer constants, which should I use?
please give me some tips for the placement in the TCS.
What is static and volatile in c?
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402