write a program for size of a data type without using
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 ) ) );
}
this will work for any data type
Is This Answer Correct ? | 15 Yes | 8 No |
Post New Answer View All Answers
code for replace tabs with equivalent number of blanks
How is a macro different from a function?
What does the c in ctime mean?
What is boolean in c?
Why c is a mother language?
Was 2000 a leap year?
Explain how can I read and write comma-delimited text?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What is the difference between constant pointer and constant variable?
What is the use of sizeof () in c?
How can I make sure that my program is the only one accessing a file?
What is the difference between volatile and const volatile?
Is swift based on c?
What are the advantages of using linked list for tree construction?
Who is the main contributor in designing the c language after dennis ritchie?