C Programming Questions and Answers – Formatted Input – 2

«
»

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

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

advertisement

1. Which of the following doesn’t require an & for the input in scanf()?
a) char name[10];
b) int name[10];
c) float name[10];
d) all of the mentioned
View Answer

Answer: a
Explanation: None.

2. Which of the following is an invalid method for input?
a) scanf(“%d%d%d”,&a, &b, &c);
b) scanf(“%d %d %d”, &a, &b, &c);
c) scanf(“Three values are %d %d %d”,&a,&b,&c);
d) none of the mentioned
View Answer

Answer: d
Explanation: None.
advertisement
advertisement

3. 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, …)
View Answer

Answer: b
Explanation: None.

4. What does scanf() function return?
a) Number of successfully matched and assigned input items
b) Nothing
c) Number of characters properly printed
d) Error
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int n;
  5.         scanf("%d", n);
  6.         printf("%d", n);
  7.     }

a) Prints the number that was entered
b) Segmentation fault
c) Nothing
d) Varies
View Answer

Answer: c
Explanation: None.
advertisement

6. What will be the output of the following C statement?

int sscanf(char *string, char *format, arg1, arg2, …)
advertisement

a) Scans the string according to the format in format and stores the resulting values through arg1, arg2, etc
b) The arguments arg1,arg2 etc must be pointers
c) Scans the string according to the format in format and stores the resulting values through arg1, arg2, etc, those arguments arg1,arg2 etc must be pointers
d) None of the mentioned
View Answer

Answer: c
Explanation: None.

7. The conversion characters d, i, o, u, and x may be preceded by h in scanf() to indicate?
a) A pointer to short
b) A pointer to long
c) Nothing
d) Error
View Answer

Answer: a
Explanation: None.

8. What will be the output of the following C code (when 4 and 5 are entered)?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int m, n;
  5.         printf("enter a number");
  6.         scanf("%d", &n);
  7.         scanf("%d", &m);
  8.         printf("%d\t%d\n", n, m);
  9.     }

a) Error
b) 4 junkvalue
c) Junkvalue 5
d) 4 5
View Answer

Answer: d
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.