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

Explain what will the preprocessor do for a program?

605


Do you know the use of 'auto' keyword?

662


Why we use void main in c?

597


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3124


Which is the memory area not included in C program? give the reason

1508






Is it possible to execute code even after the program exits the main() function?

817


Can you please explain the difference between exit() and _exit() function?

594


What does the c preprocessor do?

622


Explain what is the benefit of using const for declaring constants?

614


Which is an example of a structural homology?

785


What is selection sort in c?

611


Explain the advantages of using macro in c language?

582


Explain the difference between strcpy() and memcpy() function?

595


Which header file is used for clrscr?

582


What is #define used for in c?

615