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
How was c created?
Write a program to check palindrome number in c programming?
What is page thrashing?
i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What is the use of linkage in c language?
Why is %d used in c?
What are the types of arrays in c?
Which one would you prefer - a macro or a function?
Explain which function in c can be used to append a string to another string?
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
The difference between printf and fprintf is ?
Why can’t constant values be used to define an array’s initial size?
What was noalias and what ever happened to it?
will u please send me the placement papers to my mail???????????????????