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 (2265)
 C++ interview questions  C++ Interview Questions (1119)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (648)
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
 
errors in computer programmes are called NET 1
What is the Lvalue and Rvalue?   2
explain about storage of union elements. Bosch 2
What is 'makefile' in C langauage? How it be useful? How to write a makefile to a particular program?   2
Discuss similarities and differences of Multiprogramming OS and multiprocessing OS? TCS 4
What is a symbolic constant?   1
5) Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.without using big int and exponential function TCS 1
Write a C function to search a number in the given list of numbers. donot use printf and scanf Honeywell 6
why we are using semicolon at the end of printh statment HCL 2
how to swap two integers 1 and 32767 without using third variable Microsoft 10
what is the structure? TCS 4
what is the difference between structure and union?   3
 
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