how to find the size of the data type like int,float
without using the sizeof operator?
Answers were Sorted based on User's Feedback
Answer / vishnu948923
void main()
{
char *ptr1,*ptr2;
float fl;
ptr1 = &fl;
ptr2 = (&fl+1);
printf("%u",ptr2-ptr1);
}
Is This Answer Correct ? | 29 Yes | 15 No |
Answer / rajesh gooda
ptr manipulation will return 1.
printf("size of int is %d",(int)((int*)0 + 1))
Is This Answer Correct ? | 10 Yes | 0 No |
Answer / sunil
When the parameter is a datatype.
For Eg: sizeof(int), sizeof(double)
#define GetSize(x) (char*)((x*)10 + 1) - (char*)10
When the parameter is a variable.
For Eg: int a;
float b;
sizeof(a), sizeof(b)
#define GetSize(x) (char*)(&x + 1) - (char*)&x
Is This Answer Correct ? | 10 Yes | 4 No |
Answer / test
#include<stdio.h>
main()
{
int kh[2]={10,20};
int * ptr_kh=kh;
printf("%d",((char* )(ptr_kh+1)-(char*)ptr_kh));
}
Is This Answer Correct ? | 4 Yes | 2 No |
Answer / 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 |
Answer / amit ranjan
int main()
{
int a[2];
int one = a;
int two = a+1;
int test = two-one;
printf("%d\n", test);
return 0;
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / amit prakash
main()
{
int a;
int *aa,*bb;
int size;
aa = &a;
bb=aa;
bb++;
size=bb-aa;
printf("\nsize_of_int:%u",size) ; // actual size but
depends upon compiler
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / gururaj
Vishnu,
How can char * hold address of float????
Is This Answer Correct ? | 3 Yes | 7 No |
What does the function toupper() do?
write a c program to find largest number in matrix(in each row,each column, diagonally, and in the whole matrix)? Its urgent.
how can you print&scan anything using just one character? :) HINT: printf,scanf similer
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
simple program of graphics and their output display
What is the use of keyword VOLATILE in C?
what is difference between array of characters and string
How to add two numbers with using function?
what are the general concepts of c and c++
What is the result main() { char c=-64; int i=-32 unsigned int u =-16; if(c>i){ printf("pass1,"); if(c<u) printf("pass2"); else printf("Fail2");} else printf("Fail1); if(i<u) printf("pass2"); else printf("Fail2") } a)Pass1,Pass2 b)Pass1,Fail2 c)Fail1,Pass2 d)Fail1,Fail2 e)none
How would you rename a function in C?
c program to input values in a table(using 2D array) and print odd numbers from them