how to find that no is int or float?

Answers were Sorted based on User's Feedback



how to find that no is int or float?..

Answer / prabhat

if(sizeof(no)==2)
cout<<"Integer";
else if(sizeof(no)==4)
cout<<"Float";

Is This Answer Correct ?    5 Yes 2 No

how to find that no is int or float?..

Answer / fakkad

incomplete solution.
why? what if no is "long int" or "double"?
in that case his solution will always print float.

Is This Answer Correct ?    2 Yes 0 No

how to find that no is int or float?..

Answer / rajat bera

bool __inline is_integer(float f){
int i = f;
return (f == static_cast<float>(i));
}


int main()
{
int num=0;
double num2= 1234;

num=num2;

if(is_integer(num2))

printf("the number is int");
else
printf("the number is float");

getch();


return 0;

}

Is This Answer Correct ?    1 Yes 0 No

how to find that no is int or float?..

Answer / vignesh1988i

one way according to me is to find through the no. of bytes allocated for that variable or the value itself directly...........


thank u

Is This Answer Correct ?    1 Yes 1 No

how to find that no is int or float?..

Answer / srv

Using sizeof() operator.


if(sizeof(no)==2)
cout<<"no is int";
else
cout<<"float";

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C Interview Questions

What is header file definition?

0 Answers  


Who is the founder of c language?

0 Answers  


The differences between Windows XP and Windows Visa

8 Answers   HCL,


Explain what are multibyte characters?

0 Answers  


write a program to find the frequency of a number

4 Answers   Infosys,






what are the different storage classes in c?

0 Answers   TCS,


What is the purpose of main() function?

0 Answers  


Why void main is used in c?

0 Answers  


write a program that uses point of sale system. which are mainly used by retail markets, where the is a database inventory list, a slip should be printed for the customer. manage should be able to access what has been sold and what is left from stock?

1 Answers  


Why is %d used in c?

0 Answers  


Can you apply link and association interchangeably?

0 Answers   InterGraph,


is c language is a object oreinted language?

5 Answers   TCS,


Categories