Library Functions Questions

Practice Library Functions MCQs with answers and explanations. Page 1 of 1.

Category
C Programming
Topic
Library Functions
Page
1 / 1
Mode
Practice

Questions

Open any question to view the answer and explanation.

C standard I/O library: what does rewind(stream) do to a file stream? Choose the most accurate behavior per ISO C for a valid open stream.
Open
View answer
C strings: which standard library function finds the last occurrence of a character in a string? Pick the correct function name used to search from the end.
Open
View answer
C headers: in which header are input/output function prototypes and macros defined? Choose the correct standard header for stdio APIs.
Open
View answer
C stdio: can fprintf be used to display output on the screen? If yes, how would you direct output to the console?
Open
View answer
C standard streams: what is stderr? Choose the most accurate description used in ISO C.
Open
View answer
C stdio buffers: what is the purpose of fflush? Choose the best description of how fflush operates on streams.
Open
View answer
Turbo C (DOS): what does randomize() do? Legacy compiler question about seeding the pseudo-random generator.
Open
View answer
C conversion utilities: does a function exist to convert int or float to a string (text)? Answer with the standard-library perspective and common practice.
Open
View answer
In C, what does this code print when comparing only the first two bytes? #include<stdio.h> #include<string.h> int main() { char dest[] = {97, 97, 0}; // "aa\0" char src[] = "aaa"; // "aaa\0" int i; if ((i = memcmp(dest, src, 2)) == 0) printf("Got it"); else printf("Missed"); return 0; } Choose the observed output.
Open
View answer
In C, scanf returns the number of successful assignments. What does this program print (assume the user types two valid integers)? #include<stdio.h> int main() { int i; i = scanf("%d %d", &i, &i); printf("%d ", i); return 0; }
Open
View answer
Consider the following C code using math.h: #include<stdio.h> #include<math.h> int main() { float i = 2.5; printf("%f, %d", floor(i), ceil(i)); return 0; } What output is most consistent with typical platform behavior, noting the incorrect format specifier for ceil?
Open
View answer
In the C standard library, what does the function gcvt do?
Open
View answer
In C, printf returns the number of characters written. What does this program print (conceptual order of outputs)? #include<stdio.h> int main() { int i; i = printf("How r u "); i = printf("%d ", i); printf("%d ", i); return 0; } Assume a standard ASCII environment.
Open
View answer
In C, what happens with ungetc and which stream does it apply to? Consider the program below when the user provides the character 'b' as input each time. #include<stdio.h> int main() { int i; char c; for(i=1; i<=5; i++) { scanf("%c", &c); /* given input is 'b' */ ungetc(c, stdout); printf("%c", c); ungetc(c, stdin); } return 0; } Choose the best description of the visible output.
Open
View answer
Predict the output when using ungetc correctly on stdin. The user repeatedly inputs the character 'a': #include<stdio.h> int main() { int i; char c; for(i=1; i<=5; i++) { scanf("%c", &c); /* given input is 'a' */ printf("%c", c); ungetc(c, stdin); } return 0; } What is printed?
Open
View answer
In C, what will this program print? #include<stdio.h> #include<stdlib.h> int main() { char *i = "55.555"; int result1 = 10; float result2 = 11.111f; result1 = result1 + atoi(i); result2 = result2 + atof(i); printf("%d, %f", result1, result2); return 0; } Assume default float formatting with six digits after the decimal.
Open
View answer

Practice smarter

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