C Programming Multiple Choice Questions and Answers on Formatted Input Function scanf() for Freshers

1. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int n;
  5.         scanf("%d", n);
  6.         printf("%d\n", n);
  7.         return 0;
  8.     }
a) Compilation error
b) Undefined behavior
c) Whatever user types
d) Depends on the standard
Answer: b
2. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char *n;
  5.         scanf("%s", n);
  6.         return 0;
  7.     }
a) Compilation error
b) Undefined behavior
c) Nothing
d) None of the mentioned
Answer: b
3. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char n[] = "hellonworld!";
  5.         char s[13];
  6.         sscanf(n, "%s", s);
  7.         printf("%s\n", s);
  8.         return 0;
  9.     }
a) hellonworld!
b) hello
    world!
c) hello
d) hello world!
Answer: c
4. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         short int i;
  5.         scanf("%hd", &i);
  6.         printf("%hd", i);
  7.         return 0;
  8.     }
a) Compilation error
b) Undefined behavior
c) Whatever user types
d) None of the mentioned
Answer: c
5. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         short int i;
  5.         scanf("%*d", &i);
  6.         printf("%hd", i);
  7.         return 0;
  8.     }
a) Compilation error
b) Somegarbage value
c) Whatever user types
d) Depends on the standard
Answer: b
6. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         short int i;
  5.         scanf("%*hd", &i);
  6.         printf("%hd", i);
  7.         return 0;
  8.     }
a) Compilation error
b) Somegarbage value
c) Whatever user types
d) Depends on the standard
Answer: b
7. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         short int i;
  5.         scanf("%h*d", &i);
  6.         printf("%hd", i);
  7.         return 0;
  8.     }
a) Compilation error
b) Undefined behavior
c) Somegarbage value
d) Depends on the standard.
Answer: a
8. Which of the following is NOT a delimiter for an input in scanf?

a) Enter
b) Space
c) Tab
d) None of the mentioned
Answer: d
9. If the conversion characters of int d, i, o, u and x are preceded by h, it indicates?

a) A pointer to int
b) A pointer to short
c) A pointer to long
d) A pointer to char
Answer: b
10. 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
Answer: a
11. 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
Answer: d
12. 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, …)
Answer: b
13. scanf returns as its value

a) Number of successfully matched and assigned input items
b) Nothing
c) Number of characters properly printed
d) Error
Answer: a
14. What is the output of this C code?
  1.     #include 
  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
Answer: c
15. int sscanf(char *string, char *format, arg1, arg2, …)

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
Answer: c
16. 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
Answer: a
17. What is the output of this C code (when 4 and 5 are entered)?
  1.     #include 
  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
Answer: d

Related

Multiple Choice Questions 7917216467816453156

Post a Comment

emo-but-icon

item