Floating Point Issues Questions

Practice Floating Point Issues MCQs with answers and explanations. Page 1 of 1.

Category
C Programming
Topic
Floating Point Issues
Page
1 / 1
Mode
Practice

Questions

Open any question to view the answer and explanation.

C programming and IEEE-754 float on little-endian (Intel) The binary equivalent of 5.375 in normalized IEEE-754 single-precision form is: 0100 0000 1010 1100 0000 0000 0000 0000 Given the following C program, what output bytes (one per line, hex, least-significant address first on Intel) will be printed? #include<stdio.h> #include<math.h> int main() { float a = 5.375; char p; int i; p = (char)&a; for (i = 0; i <= 3; i++) printf("%02x ", (unsigned char)p[i]); return 0; }
Open
View answer
In C language, how will you treat the constant 3.14 explicitly as a long double literal? Add the correct type suffix to the numeric constant so the compiler stores it as long double.
Open
View answer
In C language, how will you treat the constant 3.14 explicitly as a float literal? Use the correct single-letter suffix that converts a double literal into a float.
Open
View answer
In C and computer architecture contexts, what is the binary representation of the decimal number 5.375? Express the integer and fractional parts correctly in base-2 form.
Open
View answer
We want to round off a float variable x to the nearest int value in C. Choose the correct, commonly used expression for positive values of x.
Open
View answer
In C, which statement correctly obtains the remainder when dividing the floating values 5.5 by 1.3? Select the standard-library function designed for floating remainders.
Open
View answer
Which range corresponds to long double on Turbo C under 16-bit DOS (extended-precision format)? Choose the option that matches the typical 80-bit extended range.
Open
View answer
A float occupies 4 bytes. If the hexadecimal values of these 4 bytes are A, B, C, and D, in what order are they stored in memory? Consider hardware endianness when determining byte order.
Open
View answer
Which header should be added so that the following program using log(36.0) compiles and links correctly? #include<stdio.h> int main() { printf("%f ", log(36.0)); return 0; }
Open
View answer
In standard C, which are the real (floating) data types available? Identify all floating types supported by the language.
Open
View answer
Observe the formatted-output behavior in C for a float value. Given: #include<stdio.h> int main() { float d = 2.25; printf("%e,", d); printf("%f,", d); printf("%g,", d); printf("%lf", d); return 0; } What is the exact output (spacing and commas as shown)?
Open
View answer
Pointer size question across platforms: Given #include<stdio.h> int main() { float p; printf("%d ", sizeof(p)); return 0; } What is sizeof(float) typically on 16-bit versus 32-bit compilers?
Open
View answer
Floating literal precision comparison in C: given #include<stdio.h> int main() { float a = 0.7; if(a < 0.7f) printf("C "); else printf("C++ "); return 0; } What will be printed (consider default promotions and literal types)?
Open
View answer
In C programming, consider floating-point comparison: #include<stdio.h> int main() { float a = 0.7; if (a < 0.7) printf("C "); else printf("C++ "); return 0; } What will be printed, given typical binary floating-point representation and usual type promotions during comparison?
Open
View answer
In C with math.h included, what does this program print? #include<stdio.h> #include<math.h> int main() { printf("%f ", sqrt(36.0)); return 0; } Assume typical IEEE-754 and default printf formatting for %f.
Open
View answer
On a typical platform where sizeof(float)=4, sizeof(double)=8, and sizeof(long double)=12, what does this program print? #include<stdio.h> #include<math.h> int main() { printf("%d, %d, %d ", sizeof(3.14f), sizeof(3.14), sizeof(3.14l)); return 0; } Assume long double uses extended precision storage occupying 12 bytes.
Open
View answer
With math.h functions, what is the output of this code? #include<stdio.h> #include<math.h> int main() { float n = 1.54; printf("%f, %f ", ceil(n), floor(n)); return 0; } Assume default %f precision.
Open
View answer
Given a float f = 43.20, what do these printf conversions produce? #include<stdio.h> int main() { float f = 43.20; printf("%e, ", f); printf("%f, ", f); printf("%g", f); return 0; } Assume typical IEEE-754 and default precisions for %e, %f, and %g.
Open
View answer
What is printed after casting a float to int in C? #include<stdio.h> int main() { float fval = 7.29; printf("%d ", (int)fval); return 0; } Assume standard C semantics for casts and printf.
Open
View answer

Practice smarter

Solve a few questions daily and revisit weak topics regularly to improve accuracy.