C MCQs: Standard Input and Output- Part 2

Welcome to MCQ QUIZ for preperation for C programming tests for various interviews:

 

Here is a listing of C interview questions on “Standard Input & Output” along with answers, explanations and/or solutions:

1. Which is true about function tolower?
a) The function tolower is defined in
b) Converts an upper case letter to lower case
c) returns other characters untouched
d) None of the mentioned

2. What is the output of this C code?

#include
 int main()
 {
 char c = '�';
 putchar(c);
 }

a) Compile time error
b) Nothing
c) 0
d) Undefined behaviour

3. putchar(c) function/macro always outputs character c to the
a) screen
b) standard output
c) depends on the compiler
d) Depends on the standard

4. What is the output of this C code if
following commands are used to run(considering myfile exists)?
gcc -otest test.c
./test < myfile

#include
 int main()
 {
 char c = 'd';
 putchar(c);
 }

a) Compile time error (after first command)
b) d in the myfile file
c) d on the screen
d) Undefined behaviour

5. What is the output of this C code if
following commands are used to run(considering myfile exists)?
gcc -otest test.c
./test > myfile

#include
 int main(int argc, char **argv)
 {
 char c = 'd';
 putchar(c);
 printf(" %d\n", argc);
 }

a) d 2 in myfile
b) d 1 in myfile
c) d in myfile and 1 in screen
d) d in myfile and 2 in screen


6. What is the output of this C code if
following commands are used to run and if myfile does not exist?
gcc -o test test.c
./test > myfile

#include
 int main(int argc, char **argv)
 {
 char c = 'd';
 putchar(c);
 printf(" %d\n", argc);
 }

a) d 2 in myfile
b) d 1 in myfile
c) Depends on the system
d) Depends on the standard

7. The statement prog <infile causes
a) prog to read characters from infile.
b) prog to write characters to infile.
c) infile to read characters from prog instead.
d) Nothing

Next –> C MCQs: Formatted Output – Part 1

Leave a Reply