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

Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.

0 Answers  


What is RAM memory? and What is ROM?Who designed one is temparary and another is permanent?why they designed like that?By using far pointer which type data(whether hexadecimal)we can access?

1 Answers   Excel,


Write a program to find the number of times that a given word(i.e. a short string) occurs in a sentence (i.e. a long string!). Read data from standard input. The first line is a single word, which is followed by general text on the second line. Read both up to a newline character, and insert a terminating null before processing. Typical output should be: The word is "the". The sentence is "the cat sat on the mat". The word occurs 2 times.

0 Answers  


please give me some tips for the selection in TCS.

3 Answers   TCS,


what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

0 Answers  






the maximum value that an integer constant can have is a) -32767 b) 32767 c) 1.701e+38 d) -1.7014e+38

1 Answers  


What is unsigned int in c?

0 Answers  


How can you increase the size of a statically allocated array?

0 Answers   TISL,


What is conio h in c?

0 Answers  


Tell me what is the purpose of 'register' keyword in c language?

0 Answers  


What is difference between static and global variable in c?

0 Answers  


What does %p mean?

0 Answers  


Categories