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 are the types of pointers in c?
Why should I prototype a function?
Explain what is a pragma?
What are header files in c programming?
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
What do you mean by a local block?
What's the right way to use errno?
How can you tell whether a program was compiled using c versus c++?
stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
What is the purpose of void pointer?
what is bit rate & baud rate? plz give wave forms
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
Explain what is the difference between a free-standing and a hosted environment?
Can include files be nested? How many levels deep can include files be nested?