In any given situation, one of those answers will be right and the other wrong. That said, there are programming languages, such as JavaScript, in which bit float is the only numeric data type. You have to explicitly truncate some division results to get the same semantics as Java int. Languages such as Java that support integer types make truncation automatic for integer variables.
In addition to having different semantics from double , int arithmetic is generally faster, and the smaller size 32 bits vs. Operations on integers are exact. Just different tools for different purposes. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Difference between int and double Ask Question. Precision is the main difference where float is a single precision 32 bit floating point data type, double is a double precision 64 bit floating point data type and decimal is a bit floating point data type.
More info Difference between int and double Brian. The original program won't work when x is double. Line 12 intends to break out of the loop when x equals l. You can't count on that ever happening -- don't ever try to compare floating point numbers for equality or not-equals. Refer to what every computer scientist should know about floating-point arithmetic. For the same reason, it is only bad luck that the program worked when x is an integer.
I say bad luck because if it had failed the OP would have been led to change the algorithm. Xillez, you have float and double reversed. Use double for the highest precision. In fact, for most applications there is no need to use float at all.
Mathan L 1. You can't say an int is 4 bytes and a double is 10 bytes since the size of the type is not specified in the C language specs. The correct answer is that sizeof int and sizeof double will give the correct answer for your compiler.
Other compilers may give other answers. Sherin 77 64KB. It stores 2 bit Int stores interger values like 1,2,3,4,-1,6 double double when you need fractional numbers and you've no reason to use anything else; Double data type is used to store numbers. It stores 8 bit Double is same like float but with a bigger memory size.
SioSio MB. When incrementing a double type variable, errors digit loss are accumulated. SAT Exam Prep. ACT Exam Prep. College Resources. AP Trivia. Sign in Sign up. AP Comp Sci A. Frequently Asked Questions. Here, myVar is a variable of int integer type. The size of int is 4 bytes. Integers are whole numbers that can have both zero, positive and negative values but no decimal values.
For example, 0 , -5 , The size of int is usually 4 bytes 32 bits. And, it can take 2 32 distinct states from to The size of float single precision float data type is 4 bytes. And the size of double double precision float data type is 8 bytes. It means "nothing" or "no type". You can think of void as absent. For example, if a function is not returning anything, its return type should be void.
Here variables a and b can store integer values. And, c can store a floating-point number. In C, signed and unsigned are type modifiers.
0コメント