how to find that no is int or float?
Answers were Sorted based on User's Feedback
Answer / prabhat
if(sizeof(no)==2)
cout<<"Integer";
else if(sizeof(no)==4)
cout<<"Float";
| Is This Answer Correct ? | 5 Yes | 2 No |
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 |
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 |
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 |
Answer / srv
Using sizeof() operator.
if(sizeof(no)==2)
cout<<"no is int";
else
cout<<"float";
| Is This Answer Correct ? | 1 Yes | 4 No |
Why is void main used?
What is the use of function overloading in C?
how to write a c program to print list of fruits in alpabetical order?
What are header files in c programming?
what are you see during placement time in the student.
0 Answers Goldman Sachs, TCS, Tech Solutions,
DIFFERNCE BETWEEN THE C++ AND C LANGUAGE?
Discuss the function of conditional operator, size of operator and comma operator with examples.
You have an array of n integers, randomly ordered with value 1 to n-1.The array is such that there is only one and one value occurred twice. How will you find this number?
what is difference between ++(*p) and (*p)++
17 Answers Accenture, HCL, IBM,
how to construct a simulator keeping the logical boolean gates in c
Are c and c++ the same?
what will be the output off the following program? #include<stdio.h> int main() { int a; a=015+0*71+5; printf("%d,a"); return0; }