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
What is the meaning of 2d in c?
What are the types of bitwise operator?
What is getch c?
What is the maximum no. of arguments that can be given in a command line in C.?
What are external variables in c?
Do array subscripts always start with zero?
What is the advantage of a random access file?
Why is struct padding needed?
how to print the character with maximum occurence and print that number of occurence too in a string given ?
What are local variables c?
Ow can I insert or delete a line (or record) in the middle of a file?
Which is more efficient, a switch statement or an if else chain?
how to find anagram without using string functions using only loops in c programming
How can I use a preprocessorif expression to ?
What are keywords in c with examples?