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 most efficient way to count the number of bits which are set in a value?

4 Answers  


#include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } what will happen if you executed this code?

4 Answers   Ramco,


Place the #include statement must be written in the program?

0 Answers  


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

0 Answers  


to write a program, that finds the minimum total number of shelves, including the initial one, required for this loading process. The packets are named A, B, C, D, E &#133;&#133;.. Any numbers of packets with these names could be kept in the shelf, as in this example: [ZZLLAAJKRDFDDUUGGYFYYKK]. All packets are to be loaded on cars. The cars are lined in order, so that the packets could be loaded on them. The cars are also named [A, B, C, D, E,&#133;&#133;&#133;&#133;.].

2 Answers   Infosys, TCS,


To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

0 Answers   HCL,


where do we use volatile keyword?

1 Answers  


Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80

0 Answers  


What is pointer and structure in c?

0 Answers  


Find greatest number out of 10 number without using loop.

5 Answers   TCS,


What is the use of pragma in embedded c?

0 Answers  


in iso what are the common technological language?

0 Answers  


Categories