Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Control string specifies the type and format of the data that has to be obtained from the keyboard.(a) true(b) falseThis question was addressed to me at a job interview.I'm obligated to ask this question of scanf topic in portion Input and Output in C of C

Answer»

Correct choice is (a) true

For explanation: The CONTROL STRING specifies the TYPE and format of the data that has to be obtained from the keyboard and store in the memory locations pointed by the arguments arg1,arg2….argn.

2.

Select the correct value of i from given options i=scanf("%d %d", &a, &b);(a) 1(b) 2(c) 3(d) No value assignedThe question was asked during an online interview.Asked question is from scanf topic in portion Input and Output in C of C

Answer»

The CORRECT answer is (b) 2

Easiest explanation - i STORES the number of read DATA from the stream. It is useful for detecting an error in data input.

3.

The syntax of printf() function is printf(“control string”, variable list) ;what is the prototype of the control string?(a) %[flags][.precision][width][length]specifier(b) %[flags][length][width][.precision]specifier(c) %[flags][width][.precision][length]specifier(d) %[flags][.precision][length][width]specifierThis question was addressed to me in an interview for job.The question is from printf topic in chapter Input and Output in C of C

Answer»

Right choice is (C) %[flags][WIDTH][.precision][LENGTH]specifier

Explanation: The prototype of control STRING is %[flags][width][.precision][length]specifier. Each control string MUST begin with % sign.

4.

Which mathematical function among the following does NOT require int parameters?(a) div(x, y);(b) srand(x);(c) sqrt(x);(d) all of the mentionedThis question was posed to me in quiz.This key question is from Mathematical Functions topic in chapter Input and Output in C of C

Answer»

Correct CHOICE is (c) sqrt(X);

Easiest EXPLANATION - NONE.

5.

fputs() function writes a string to a file that only ends with a newline.(a) True(b) False(c) Depends on the standard(d) Depends on the compilerThis question was posed to me during an interview.My query is from Line Input & Output topic in chapter Input and Output in C of C

Answer»

The CORRECT ANSWER is (b) False

The BEST explanation: NONE.

6.

The syntax of fgets is char *fgets(char *line, int maxline, FILE *fp). Which is true for fgets?(a) Returns line on success(b) On end of file or error it returns NULL(c) Nothing(d) Both returns line on success & On end of file or error it returns NULLI had been asked this question in an internship interview.I'm obligated to ask this question of Line Input & Output in section Input and Output in C of C

Answer»

The correct answer is (d) Both RETURNS line on success & On END of FILE or error it returns NULL

Easy explanation - None.

7.

In a variable length argument function, the declaration “…” can _______(a) Appear anywhere in the function declaration(b) Only appear at the end of an argument list(c) Nothing(d) None of the mentionedI had been asked this question by my school teacher while I was bunking the class.My enquiry is from Variable Length Argument in section Input and Output in C of C

Answer»

Correct CHOICE is (b) Only APPEAR at the END of an argument list

The EXPLANATION is: None.

8.

What is the purpose of sprintf?(a) It prints the data into stdout(b) It writes the formatted data into a string(c) It writes the formatted data into a file(d) None of the mentionedI got this question during an interview for a job.This interesting question is from Formatted Output topic in section Input and Output in C of C

Answer»

The correct OPTION is (B) It writes the FORMATTED DATA into a string

Best explanation: NONE.

9.

What is the qualifying input for the type specifier G?(a) floating point numbers(b) floating point numbers in exponential format(c) floating point numbers in the shorter of exponential format(d) not a type specifierThe question was posed to me in an international level competition.Query is from scanf in division Input and Output in C of C

Answer»

The CORRECT OPTION is (c) floating point numbers in the shorter of exponential format

The best EXPLANATION: G is a type specifier used to TAKE an input of floating point numbers in the shorter of exponential format.

10.

What is the prototype of scanf function?(a) scanf("controlstring",arg1,arg2,arg3,….,argn);(b) scanf("control string", variable list);(c) scanf(" varible list,", control string);(d) scanf("arg1,arg2,arg3,….,argn", control string);This question was addressed to me in an interview for internship.This interesting question is from scanf topic in division Input and Output in C of C

Answer» RIGHT choice is (a) scanf("CONTROLSTRING",ARG1,arg2,arg3,….,ARGN);

The explanation: The SYNTAX of the scanf() can be given as,scanf("control string", arg1,arg2,arg3,….,argn);
11.

The maximum number of characters to be printed is specified by __________(a) precision(b) width(c) length(d) flagsI have been asked this question in an online quiz.I'm obligated to ask this question of printf topic in section Input and Output in C of C

Answer» CORRECT option is (a) precision

Explanation: Precision SPECIFIES the MAXIMUM NUMBER of characters to PRINT.
12.

Which of the following snippet will effectively generate random numbers?(a) rand();(b) rand(10);(c) rand(time(NULL));(d) all of the mentionedI got this question in an interview for internship.Enquiry is from Random Number Generation in division Input and Output in C of C

Answer»

Right ANSWER is (a) rand();

The best I can EXPLAIN: NONE.

13.

What type of inputs are accepted by mathematical functions?(a) short(b) int(c) float(d) doubleThis question was addressed to me during a job interview.My question is taken from Mathematical Functions in division Input and Output in C of C

Answer» RIGHT ANSWER is (d) double

The EXPLANATION: NONE.
14.

Whichfunctions is declared in ?(a) fseek()(b) ftell()(c) ferror()(d) fsetpos()This question was posed to me during an online interview.Asked question is from File Operations in division Input and Output in C of C

Answer»

Right option is (C) ferror()

To explain I would say: ferror()is declared under . ferror()RETURNS non-zero if the error indicator for stream is SET.

15.

what is the function of fputs()?(a) read a line from a file(b) read a character from a file(c) write a character to a file(d) write a line to a fileThe question was posed to me in exam.The origin of the question is File Operations in division Input and Output in C of C

Answer»

The correct option is (d) WRITE a line to a file

Easy explanation - The fputs()is USED to write a line to a file. fputs()syntax can be WRITTEN as

int fputs(CONST char *str, FILE *stream);

16.

If the mode includes b after the initial letter, what does it indicates?(a) text file(b) big text file(c) binary file(d) blueprint textI got this question in exam.My question is from File Operations topic in division Input and Output in C of C

Answer»

The correct OPTION is (c) binary FILE

Explanation: If the mode consists of letter b after the FIRST letter as in, “rb” or “w+b”, it INDICATES binary file.

17.

Output justification such as decimal point, numerical sign, trailing zeros or octal are specified.(a) specifier(b) flags(c) precision(d) decimalI got this question in examination.Origin of the question is printf in chapter Input and Output in C of C

Answer»

The CORRECT option is (b) flags

Easiest explanation - Flags SPECIFY output justification such as Left-justify within the DATA given field width, Displays the data with its numeric sign, used to provide additional specifiers LIKE o, x, X for octal, left PADDING of a number.

18.

Only _____character of pushback is guaranteed per file when ungetc is used.(a) Two(b) One(c) Many(d) ZeroI have been asked this question by my college director while I was bunking the class.This interesting question is from Ungetc topic in portion Input and Output in C of C

Answer»

The CORRECT OPTION is (B) One

Explanation: NONE.

19.

what is the return value of fputs()?(a) EOF if an error occurs(b) Non-negative if no error(c) EOF if an error occurs & Non-negative if no error(d) None of the mentionedThe question was posed to me by my school teacher while I was bunking the class.This key question is from Line Input & Output topic in division Input and Output in C of C

Answer»

The correct option is (C) EOF if an ERROR occurs & Non-negative if no error

To explain I WOULD say: NONE.

20.

stdout, stdin and stderr are ________(a) File pointers(b) File descriptors(c) Streams(d) StructureThis question was addressed to me in unit test.I need to ask this question from File Access topic in portion Input and Output in C of C

Answer»

The CORRECT OPTION is (a) FILE pointers

To EXPLAIN: NONE.

21.

Which of the following fopen() statements are illegal?(a) fp = fopen(“abc.txt”, “r”);(b) fp = fopen(“/home/user1/abc.txt”, “w”);(c) fp = fopen(“abc”, “w”);(d) none of the mentionedThe question was posed to me in quiz.My enquiry is from File Access in chapter Input and Output in C of C

Answer» CORRECT ANSWER is (d) NONE of the mentioned

The BEST EXPLANATION: None.
22.

Explain the format string "%5d%s %c"(a) five characters as a decimal integer, then reads the remaining as a string and then scans the first non-whitespace character(b) compile error(c) run-time error(d) read first five characters as a decimal and ignore the restThis question was addressed to me by my college professor while I was bunking the class.The question is from scanf topic in division Input and Output in C of C

Answer»

The correct option is (a) five CHARACTERS as a DECIMAL INTEGER, then reads the remaining as a STRING and then scans the first non-whitespace character

To explain I would say: The above format string reads the first five characters as a decimal integer, then reads the remaining as a string until a space, newline or TAB is found, then reads the first non-whitespace character.

23.

Which is the correct way to generate numbers between minimum and maximum(inclusive)?(a) minimum + (rand() % (maximum – minimum));(b) minimum + (rand() % (maximum – minimum + 1));(c) minimum * (rand() % (maximum – minimum))(d) minimum – (rand() % (maximum + minimum));The question was posed to me during a job interview.The doubt is from Random Number Generation in section Input and Output in C of C

Answer»

The correct option is (b) minimum + (RAND() % (maximum – minimum + 1));

To EXPLAIN: NONE.

24.

The standard header _______ is used for variable list arguments (…) in C.(a) (b) (c) (d) I have been asked this question during an interview.My question is taken from Variable Length Argument in division Input and Output in C of C

Answer»

The CORRECT OPTION is (d)

The BEST EXPLANATION: NONE.

25.

Which of the following macro extracts an argument from the variable argument list (ie ellipsis) and advance the pointer to the next argument?(a) va_list(b) va_arg(c) va_end(d) va_startThis question was addressed to me in an internship interview.The query is from Variable Length Argument in section Input and Output in C of C

Answer»

The CORRECT choice is (B) va_arg

To explain I would SAY: NONE.

26.

What error will be generated on using incorrect specifier for the datatype being read?(a) compile error(b) run-time error(c) logical error(d) no errorThe question was asked during a job interview.My question is taken from scanf in portion Input and Output in C of C

Answer» RIGHT option is (b) run-time ERROR

The explanation is: Using an incorrect SPECIFIER for the datatype being READ will generate a run-time error.
27.

The functions vprintf(), vfprintf(), and vsprintf() are not equivalent to the corresponding printf() functions exceptthe variable argument list.(a) true(b) falseI had been asked this question in exam.My question is from File Operations in section Input and Output in C of C

Answer»

Correct choice is (B) false

To explain I would SAY: The functions vprintf() , vfprintf() , and VSPRINTF() are similar to the corresponding printf() functions exceptthat the variable ARGUMENT list is replaced by arg.

28.

What action is carried out by scanf if a user enters any blank spaces, tabs, and newlines?(a) consider as input(b) ignores it(c) produces error(d) nothing can be saidThe question was posed to me in an online interview.Asked question is from scanf in division Input and Output in C of C

Answer»

The correct option is (b) ignores it

The explanation: The scanf() FUNCTION ignores any blank spaces, TABS, and NEWLINES entered by the user. This scanf() function just returns the NUMBER of input fields successfully scanned and STORED.

29.

Which of the following can be used for random number generation?(a) random()(b) rnd()(c) rndm()(d) none of the mentionedI had been asked this question during an online exam.Asked question is from Random Number Generation topic in section Input and Output in C of C

Answer» CORRECT CHOICE is (a) random()

To explain I WOULD say: NONE.
30.

What will sin(x) returns?(a) sine of x where x is in radians(b) sine of x where x is in degree(c) cosine of x where x is in radians(d) cosine of x where x is in degreeI have been asked this question in final exam.Asked question is from Mathematical Functions topic in section Input and Output in C of C

Answer»

Correct OPTION is (a) SINE of X where x is in radians

Easy EXPLANATION - NONE.

31.

Memory allocation using malloc() is done in _________(a) Static area(b) Stack area(c) Heap area(d) Both Stack & Heap areaThe question was posed to me in semester exam.My question is taken from Storage Management topic in division Input and Output in C of C

Answer»

Right choice is (C) HEAP area

For EXPLANATION: None.

32.

void * malloc(size_t n) returns?(a) Pointer to n bytes of uninitialized storage(b) NULL if the request can be satisfied(c) Nothing(d) None of the mentionedThe question was posed to me in an online quiz.My doubt stems from Storage Management in chapter Input and Output in C of C

Answer»

Correct ANSWER is (a) POINTER to N bytes of uninitialized storage

Explanation: NONE.

33.

Which of the following is the correct declaration for ungetc?(a) int ungetc(int c, FILE fp);(b) int ungetc(int *c, FILE fp);(c) int ungetc(int c, FILE *fp);(d) int ungetc(int *c, FILE *fp);I had been asked this question in a job interview.I need to ask this question from Ungetc in section Input and Output in C of C

Answer»

Right CHOICE is (c) int ungetc(int c, FILE *fp);

EASY explanation - None.

34.

String operation such as strcat(s, t), strcmp(s, t), strcpy(s, t) and strlen(s) heavily rely upon.(a) Presence of NULL character(b) Presence of new-line character(c) Presence of any escape sequence(d) None of the mentionedThis question was posed to me in an online quiz.My question is from String Operations in portion Input and Output in C of C

Answer»

The correct choice is (a) Presence of NULL character

Best EXPLANATION: NONE.

35.

Which function has a return type as char pointer?(a) getline(b) fputs(c) fgets(d) all of the mentionedThis question was addressed to me during an interview for a job.This question is from Line Input & Output topic in section Input and Output in C of C

Answer» CORRECT CHOICE is (C) fgets

The EXPLANATION: NONE.
36.

What is FILE reserved word?(a) A structure tag declared in stdio.h(b) One of the basic data types in c(c) Pointer to the structure defined in stdio.h(d) It is a type name defined in stdio.hThis question was posed to me in an online interview.This intriguing question originated from File Access in portion Input and Output in C of C

Answer»

Correct CHOICE is (d) It is a TYPE name DEFINED in stdio.h

The EXPLANATION: None.

37.

What are the first and second arguments of fopen?(a) A character string containing the name of the file & the second argument is the mode(b) A character string containing the name of the user & the second argument is the mode(c) A character string containing file pointer & the second argument is the mode(d) None of the mentionedThis question was addressed to me by my college professor while I was bunking the class.The question is from File Access in chapter Input and Output in C of C

Answer»

The correct choice is (a) A character string containing the name of the FILE & the SECOND argument is the mode

The best explanation: NONE.

38.

What are the Properties of the first argument of a printf() functions?(a) It is defined by a user(b) It keeps the record of the types of arguments that will follow(c) There may no be first argument(d) None of the mentionedThe question was posed to me in an international level competition.This interesting question is from Formatted Output in chapter Input and Output in C of C

Answer» RIGHT ANSWER is (b) It KEEPS the record of the types of arguments that will follow

The explanation is: NONE.
39.

What does scanf() function return?(a) Number of successfully matched and assigned input items(b) Nothing(c) Number of characters properly printed(d) ErrorThe question was asked in my homework.My question is based upon Formatted Input in chapter Input and Output in C of C

Answer»

The CORRECT option is (a) NUMBER of SUCCESSFULLY matched and ASSIGNED input items

The EXPLANATION is: None.

40.

What will the given code result in printf(“\n you are\”awesome \" ");?(a) compile error(b) run-time error(c) you are "awesome"(d) you are awesomeI have been asked this question in a job interview.This is a very interesting question from printf in portion Input and Output in C of C

Answer»

The correct option is (C) you are "awesome"

To explain I would say: The above given CODE uses \”\” to display the word within double INVERTED commas on standard output screen.

41.

What is the size of array “line” used in fgets(line, maxline, *fp) function?(a) maxline – 1(b) maxline(c) maxline + 1(d) Size is dynamicThis question was posed to me by my college professor while I was bunking the class.My query is from Line Input & Output in portion Input and Output in C of C

Answer» RIGHT CHOICE is (B) maxline

The EXPLANATION: NONE.
42.

Which of the following function can be used to terminate the main() function from another function safely?(a) return(expr);(b) exit(expr);(c) abort();(d) both exit(expr); and abort();The question was asked in class test.I'd like to ask this question from Error Handling topic in portion Input and Output in C of C

Answer»

Right OPTION is (B) exit(expr);

The EXPLANATION is: None.

43.

Which is true about function tolower?(a) The function tolower is defined in (b) Converts an uppercase letter to lowercase(c) Returns other characters untouched(d) None of the mentionedThis question was addressed to me during an interview.My query is from Standard Input & Output in chapter Input and Output in C of C

Answer» RIGHT OPTION is (d) NONE of the mentioned

Best EXPLANATION: None.
44.

Which of the following represents the function for scanf()?(a) void scanf(char *format, …)(b) int scanf(char *format, …)(c) char scanf(int format, …)(d) char *scanf(char *format, …)This question was posed to me by my college director while I was bunking the class.Question is from Formatted Input in division Input and Output in C of C

Answer» CORRECT answer is (b) int scanf(char *FORMAT, …)

The BEST I can explain: None.
45.

For a typical program, the input is taken using _________(a) scanf(b) Files(c) Command-line(d) All of the mentionedThis question was addressed to me at a job interview.I would like to ask this question from Standard Input & Output topic in chapter Input and Output in C of C

Answer» RIGHT OPTION is (d) All of the mentioned

For EXPLANATION: NONE.
46.

What does tmpfile() returns when it could not create the file?(a) stream and NULL(b) only stream(c) only NULL(d) does not return anythingI had been asked this question during an interview.The above asked question is from File Operations topic in section Input and Output in C of C

Answer»

Right choice is (a) STREAM and NULL

The best I can EXPLAIN: tmpfile() RETURNS a stream or NULLif it COULD not create the FILE.

47.

_____removes the named file, so that a subsequent attempt to open it will fail.(a) remove(const *filename)(b) remove(filename)(c) remove()(d) fclose(filename)The question was asked in exam.My question is from File Operations topic in chapter Input and Output in C of C

Answer»

Correct choice is (a) REMOVE(const *filename)

EXPLANATION: remove(const *filename)removes the named FILE, so that a SUBSEQUENT attempt to OPEN it will fail. It returns non-zero of the attempt fails.

48.

fflush(NULL)flushes all ____________(a) input streams(b) output streams(c) previous contents(d) appended textThis question was posed to me at a job interview.My doubt is from File Operations topic in section Input and Output in C of C

Answer»

Correct choice is (B) OUTPUT streams

Easy EXPLANATION - fflush(FILE *stream) – fflush() causes any buffered but unwritten to be written on an Output stream. On an input stream, the effect is undefined. fflush(NULL)FLUSHES all output streams.

49.

What is the use of symbol * in the control string as shown [=%[*][width] [modifiers] type=]?(a) * is optional and used when the data should be read from the stream but ignored(b) * is not optional, used to read data from the stream but it is not ignored(c) * is not optional, it is used to read data stream but ignored(d) * is optional and used to read data from stream but it is not ignoredI had been asked this question in an online interview.Question is from scanf topic in division Input and Output in C of C

Answer»

The CORRECT choice is (a) * is optional and used when the data should be read from the stream but IGNORED

The best I can explain: * is an optional argument, it indicates that data should be read from the steam but ignored (not STORED in a MEMORY location)

50.

gets() and puts() operate on ___________(a) stdin and stdout(b) files(c) stderr(d) nothingThis question was addressed to me in a job interview.My doubt stems from Line Input & Output topic in division Input and Output in C of C

Answer» CORRECT OPTION is (a) STDIN and stdout

To EXPLAIN: NONE.