C Programming Questions and Answers – Standard Input & Output – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Standard Input & Output – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

1. Which is true about function tolower?
a) The function tolower is defined in <ctype.h>
b) Converts an uppercase letter to lowercase
c) Returns other characters untouched
d) None of the mentioned
View Answer

Answer: d
Explanation: None.

2. What will be the output of the following C code?

advertisement
advertisement
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char c = '�';
  5.         putchar(c);
  6.     }

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

Answer: b
Explanation: None.
advertisement

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
View Answer

Answer: b
Explanation: None.

4. What will be the output of the following C code if following commands are used to run (considering myfile exists)?

advertisement
  1.     gcc -otest test.c
  2.     ./test < myfile
  3.  
  4.     #include <stdio.h>
  5.     int main()
  6.     {
  7.         char c = 'd';
  8.         putchar(c);
  9.     }

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

Answer: c
Explanation: None.
advertisement

5. What will be the output of the following C code if following commands are used to run (considering myfile exists)?

  1.     gcc -otest test.c
  2.     ./test > myfile
  3.  
  4.      #include <stdio.h>
  5.     int main(int argc, char **argv)
  6.     {
  7.         char c = 'd';
  8.         putchar(c);
  9.         printf(" %d\n", argc);
  10.     }

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
View Answer

Answer: b
Explanation: 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?

  1.     gcc -o test test.c
  2.     ./test > myfile
  3.  
  4.     #include <stdio.h>
  5.     int main(int argc, char **argv)
  6.     {
  7.         char c = 'd';
  8.         putchar(c);
  9.         printf(" %d\n", argc);
  10.     }

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

Answer: b
Explanation: 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
View Answer

Answer: a
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.