how to find the size of the data type like int,float
without using the 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 ) ) );
}
It will work for any data type
Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
Lists the benefits of c programming language?
What is sizeof in c?
Are the variables argc and argv are local to main?
Explain how does flowchart help in writing a program?
Why do we use static in c?
Why & is used in c?
Does c have an equivalent to pascals with statement?
What is pivot in c?
What are reserved words?
Write a program to generate random numbers in c?
Explain what are the different file extensions involved when programming in c?
What is the general form of #line preprocessor?
How can you invoke another program from within a C program?
What is NULL pointer?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?