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


Please Help Members By Posting Answers For Below Questions

Lists the benefits of c programming language?

807


What is sizeof in c?

756


Are the variables argc and argv are local to main?

977


Explain how does flowchart help in writing a program?

848


Why do we use static in c?

810


Why & is used in c?

912


Does c have an equivalent to pascals with statement?

756


What is pivot in c?

746


What are reserved words?

845


Write a program to generate random numbers in c?

843


Explain what are the different file extensions involved when programming in c?

834


What is the general form of #line preprocessor?

760


How can you invoke another program from within a C program?

799


What is NULL pointer?

852


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?

808