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


Please Help Members By Posting Answers For Below Questions

code for replace tabs with equivalent number of blanks

1950


How is a macro different from a function?

911


What does the c in ctime mean?

829


What is boolean in c?

853


Why c is a mother language?

774


Was 2000 a leap year?

860


Explain how can I read and write comma-delimited text?

967


Which control loop is recommended if you have to execute set of statements for fixed number of times?

1124


What is the difference between constant pointer and constant variable?

1001


What is the use of sizeof () in c?

815


How can I make sure that my program is the only one accessing a file?

992


What is the difference between volatile and const volatile?

777


Is swift based on c?

894


What are the advantages of using linked list for tree construction?

880


Who is the main contributor in designing the c language after dennis ritchie?

808