ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2253)
 C++ interview questions  C++ Interview Questions (1111)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (646)
Question
how to find the size of the data type like int,float 
without using the sizeof operator?
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
void main()
{
char *ptr1,*ptr2;
float fl;
ptr1 = &fl;
ptr2 = (&fl+1);

printf("%u",ptr2-ptr1);
}
 
Is This Answer Correct ?    29 Yes 13 No
Vishnu948923
 
Answer
# 2
ptr manipulation will return 1.

printf("size of int is %d",(int)((int*)0 + 1))
 
Is This Answer Correct ?    9 Yes 0 No
Rajesh Gooda
 
 
 
Answer
# 3
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
Sunil
 
Answer
# 4
#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
Test
 
Answer
# 5
#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
Abdur Rab
 
Answer
# 6
#define SIZEOF(type) (int)&((int *)0)[1]) 
Is This Answer Correct ?    0 Yes 0 No
Anil Arya
 
Answer
# 7
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
Amit Ranjan
 
Answer
# 8
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
Amit Prakash
 
Answer
# 9
Vishnu,
How can char * hold address of float????
 
Is This Answer Correct ?    3 Yes 7 No
Gururaj
 
Answer
# 10
How can char * hold address of float???? 
Is This Answer Correct ?    0 Yes 4 No
Abc
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
What is Your Name :)   1
What is key word in c language? ABC 4
What's the difference between struct x1 { ... }; and typedef struct { ... } x2; ?   3
A woman had somany gloves and hats 22 red,34 blue, 45 white...there was power cut and she took a glove and how many gloves shud she take so that she gets a pair of glove fr each color?? TCS 3
Toggle nth bit in a given integer - num Qualcomm 5
What are pointers in C? KPIT 5
what is the difference between structure and union?   3
why r u join this company? give solid resons. Infosys 16
which of the function operator cannot be over loaded a) <= b)?: c)== d)* HCL 10
why Language C is plateform dependent Wipro 3
code for copying two strings with out strcpy() function.   6
the format specified for hexa decimal is a.%d b.%o c.%x d.%u TCS 6
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com