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

Explain what is the use of a semicolon (;) at the end of every program statement?

0 Answers  


The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none

0 Answers  


Differentiate between static and dynamic modeling.

0 Answers   Wipro,


main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(ā€œ%dā€,x); }

8 Answers   Vector,


a character or group of characters that defines a register,or a part of storage a) memory b) byte c) address d) linear list

0 Answers  






What are the different types of pointers?

4 Answers   HCL, TCS,


What is %s and %d in c?

0 Answers  


How can you return multiple values from a function?

0 Answers  


in any language the sound structure of that language depends on its a) character set, input/output function, its control structures b) character set, library functions, input/output functions its control structures c) character set, library functions, control sturctures d) character set, operators, its control structures

0 Answers  


Why is sizeof () an operator and not a function?

0 Answers  


Can anyone help me with this please? Need to print the below values.. Thanks 1 1 2 1 2 3 1 2 3 4

3 Answers  


difference between my-strcpy and strcpy ?

3 Answers   Geometric Software, IIM, Infosys,


Categories