Here is a listing of C Objective 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 uppercase letter to lowercase
c) Returns other characters untouched
d) None of the mentioned
Answer: d
Clarification: None.
2. What will be the output of the following C code?
-
#include -
int main()
-
{ -
char c = '�';
-
putchar(c);
-
}
a) Compile time error
b) Nothing
c) 0
d) Undefined behaviour
Answer: b
Clarification: None.
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
Answer: b
Clarification: None.
4. What will be the output of the following 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
Answer: c
Clarification: None.
5. What will be the output of the following 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(" %dn", 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
Answer: b
Clarification: None.
6. What will be the output of the following 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(" %dn", argc);
-
}
a) d 2 in myfile
b) d 1 in myfile
c) Depends on the system
d) Depends on the standard
Answer: b
Clarification: None.
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
Answer: a
Clarification: None.
