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
What are the 4 types of functions?
What is structure and union in c?
largest Of three Number using without if condition?
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......
What is this infamous null pointer, anyway?
Are the expressions * ptr ++ and ++ * ptr same?
What is the description for syntax errors?
What is a pointer on a pointer in c programming language?
how can use subset in c program and give more example
What does the file stdio.h contain?
Write a program to print "hello world" without using a semicolon?
Explain how can I avoid the abort, retry, fail messages?
What is a list in c?
How can I implement a delay, or time a users response, with sub-second resolution?
Do you know the purpose of 'register' keyword?