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 the output on the screen? int n; n=printf("my name is %d",printf("kiran %d",printf("kumar"))); printf("\n %d \n",n);

4 Answers   TCS,


write a c program to print "Welcome" without using semicolon in the whole program ??

15 Answers   Infosys, TCS,


my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

0 Answers  


What is the difference between CV and Resume ?

2 Answers  


diff between exptected result and requirement?

0 Answers   HCL,






#define f(x) main() { printf("\n%d",f(2+2)); }

5 Answers  


main() { char x; while(x=0;x<=255;x++) printf("\nAscii value %d Charater %c",x,x); }

2 Answers  


Write the control statements in C language

0 Answers   Atos Origin,


How to reverse alternate words in a given line of string For Eg: my name is narasimha output : my eman is ahmisaran

0 Answers  


Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as “****”.

0 Answers  


how to set Nth bit of a variable?

1 Answers  


related proverb of "dont count your chicken before it hatches"

1 Answers  


Categories