write a program for size of a data type without using
sizeof() operator?

Answer Posted / core_coder

#include <stdio.h>

struct node {
int x;
int y;
};

unsigned int find_size ( void* p1, void* p2 )
{
return ( (char*)p2 - (char*)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 ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the 4 types of functions?

576


What is structure and union in c?

605


largest Of three Number using without if condition?

1010


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

1415


What is this infamous null pointer, anyway?

613






Are the expressions * ptr ++ and ++ * ptr same?

672


What is the description for syntax errors?

619


What is a pointer on a pointer in c programming language?

623


how can use subset in c program and give more example

1507


What does the file stdio.h contain?

608


Write a program to print "hello world" without using a semicolon?

600


Explain how can I avoid the abort, retry, fail messages?

595


What is a list in c?

624


How can I implement a delay, or time a users response, with sub-second resolution?

631


Do you know the purpose of 'register' keyword?

646