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 |
What does it mean when a pointer is used in an if statement?
Write a simple program to find the size of different basic data types in C.
How can I avoid the abort, retry, fail messages?
Which of the Following will define a type NODE that is a node in a Linked list? A)struct node {NODE*next;int x;};type def struct node NODE; B)typedef struct NODE {struct NODE *next;int x;}; C)typedef struct NODE {NODE *next;int x;}; D)typedef struct {NODE *next;int x;}NODE;
Hi, main() { } Is a user defined function or Built in Functionn
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); }
write a program to remove duplicate from an ordered char array? in c
Write a program of prime number using recursion.
how to find anagram without using string functions using only loops in c programming
what is c language.
Where are c variables stored in memory?
How to add two numbers without using semicolon at runtime