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


Please Help Members By Posting Answers For Below Questions

Between macros and functions,which is better to use and why?

1571


List some of the dynamic data structures in C?

791


What are identifiers in c?

636


List a few unconditional control statement in c.

561


Why is extern used in c?

613






There seem to be a few missing operators ..

620


Does c have class?

614


What is difference between constant pointer and constant variable?

631


Does c have circular shift operators?

733


How do you redirect a standard stream?

627


What is the scope of global variable in c?

559


what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555

2538


In c programming, explain how do you insert quote characters (? And ?) Into the output screen?

766


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

1860


Tell me can the size of an array be declared at runtime?

600