C Programming Multiple Choice Questions and Answers on Standard Input & Output Functions for Freshers

https://www.computersprofessor.com/2018/01/c-programming-multiple-choice-questions.html
1. Which among the following is odd one out?
a) printf
b) fprintf
c) putchar
d) scanf
Answer: d
2. For a typical program, the input is taken using
a) scanf
b) Files
c) Command-line
d) All of the mentioned
Answer: d
3. What does the following command line signify?
prog1|prog2
prog1|prog2
a) It runs prog1 first, prog2 second
b) It runs prog2 first, prog1 second
c) It runs both the programs, pipes output of prog1 to input of prog2
d) It runs both the programs, pipes output of prog2 to input of prog1
Answer: c
4. What is the default return-type of getchar()?
a) char
b) int
C. char *
D. reading character doesn’t require a return-type
Answer: b
5. The value of EOF is_____
a) -1
b) 0
c) 1
d) 10
Answer: a
6. What is the use of getchar()?
a) The next input character each time it is called
b) EOF when it encounters end of file
c) The next input character each time it is called
EOF when it encounters end of file
d) None of the mentioned
Answer: c
7. Which is true?
a) The symbolic constant EOF is defined in
b) The value is -1
c) The symbolic constant EOF is defined in
d) Only value is -1
Answer: c
8. What is the return value of putchar()?
a) The character written
b) EOF if an error occurs
c) Nothing
d) Both character written & EOF if an error occurs
Answer: d
9. 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
Answer: d
10. 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
b) Nothing
c) 0
d) Undefined behaviour
Answer: b
11. 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
Answer: b
12. What is the output of this C code if
following commands are used to run(considering myfile exists)?
gcc -otest test.c
./test < myfile
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
b) d in the myfile file
c) d on the screen
d) Undefined behaviour
Answer: c
13. What is the output of this C code if
following commands are used to run(considering myfile exists)?
gcc -otest test.c
./test > myfile
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
b) d 1 in myfile
c) d in myfile and 1 in screen
d) d in myfile and 2 in screen
Answer: b
14. 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
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
b) d 1 in myfile
c) Depends on the system
d) Depends on the standard
Answer: b
15. The statement prog
a) prog to read characters from infile.
b) prog to write characters to infile.
c) infile to read characters from prog instead.
d) nothing
a) prog to read characters from infile.
b) prog to write characters to infile.
c) infile to read characters from prog instead.
d) nothing
Answer: a