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
Explain what will the preprocessor do for a program?
Do you know the use of 'auto' keyword?
Why we use void main in c?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
Which is the memory area not included in C program? give the reason
Is it possible to execute code even after the program exits the main() function?
Can you please explain the difference between exit() and _exit() function?
What does the c preprocessor do?
Explain what is the benefit of using const for declaring constants?
Which is an example of a structural homology?
What is selection sort in c?
Explain the advantages of using macro in c language?
Explain the difference between strcpy() and memcpy() function?
Which header file is used for clrscr?
What is #define used for in c?