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 (2254)
 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 does the following function print? func(int i) { if(i%2)return 0; eale return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i);} TCS 9
To what value do nonglobal variables default? 1) auto 2) register 3) static   4
can any one tell that i have a variable which is declared as static but i want this variable to be visible to the other files? how?   2
what is the mean of c languages. Polaris 1
How can draw a box in cprogram without using graphics.h header file & using only one printf(); ? NIIT 4
what is Structural oriented language? give some example of this language.....?   1
what is C? Syntel 9
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS? Aricent 2
why little endian and big endian came?y they using differently? y they not used commonly ?wt is application of little and big ?   1
what are bitwise shift operators?   4
How to find the given no is odd or even without checking of any condition and loops. (Hint: Using array)   4
how to find string length wihtout using c function?   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