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



how to find the size of the data type like int,float without using the sizeof operator?..

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

how to find the size of the data type like int,float without using the sizeof operator?..

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

how to find the size of the data type like int,float without using the sizeof operator?..

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

how to find the size of the data type like int,float without using the sizeof operator?..

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

how to find the size of the data type like int,float without using the sizeof operator?..

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

how to find the size of the data type like int,float without using the sizeof operator?..

Answer / anil arya

#define SIZEOF(type) (int)&((int *)0)[1])

Is This Answer Correct ?    0 Yes 0 No

how to find the size of the data type like int,float without using the sizeof operator?..

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

how to find the size of the data type like int,float without using the sizeof operator?..

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

how to find the size of the data type like int,float without using the sizeof operator?..

Answer / gururaj

Vishnu,
How can char * hold address of float????

Is This Answer Correct ?    3 Yes 7 No

how to find the size of the data type like int,float without using the sizeof operator?..

Answer / abc

How can char * hold address of float????

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More C Interview Questions

Explain what are reserved words?

0 Answers  


Is it possible to create recycle bin in mobiles?

2 Answers  


What is the use of a static variable in c?

0 Answers  


What is the c value paradox and how is it explained?

0 Answers  


what is the syallabus of computer science students in group- 1?

0 Answers  






what is the diff b/w static and non static variables in C. Give some examples plz.

3 Answers   Wipro,


what will be the result of the following program ? char *gxxx() { static char xxx[1024]; return xxx; } main() { char *g="string"; strcpy(gxxx(),g); g = gxxx(); strcpy(g,"oldstring"); printf("The string is : %s",gxxx()); } a) The string is : string b) The string is :Oldstring c) Run time error/Core dump d) Syntax error during compilation e) None of these

2 Answers   IBM,


What is wrong with this statement? Myname = 'robin';

0 Answers  


I have an array of 100 elements, each of which is a random integer. I want to know which of the elements: a) are multiples of 2 b) are multiples of 2 AND 5 c) have a remainder of 3 when divided by 7

1 Answers  


Give basis knowledge of web designing ...

0 Answers   HCL,


which one low Priority in c? a)=,b)++,c)==,d)+

10 Answers  


Can you return null in c?

0 Answers  


Categories