C Programming Multiple Choice Questions and Answers on Formatted Output Function printf() for Freshers

1. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10, j = 2;
  5.         printf("%d\n", printf("%d %d ", i, j));
  6.     }
a) Compile time error
b) 10 2 4
c) 10 2 2
d) 10 2 5
Answer: d
2. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10, j = 3;
  5.         printf("%d %d %d", i, j);
  6.     }
a) Compile time error
b) 10 3
c) 10 3 some garbage value
d) Undefined behaviour
Answer: c
3. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10, j = 3, k = 3;
  5.         printf("%d %d ", i, j, k);
  6.     }
a) Compile time error
b) 10 3 3
c) 10 3
d) 10 3 somegarbage value
Answer: c
4. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char *s = "myworld";
  5.         int i = 9;
  6.         printf("%*s", i, s);
  7.     }
a) myworld
b) myworld(note: spaces to the left of myworld)
c) myworld (note:followed by two spaces after myworld)
d) Undefined
Answer: b
5. What is the output of this C code?
  1.     #include 
  2.     int main(int argc, char** argv)
  3.     {
  4.         char *s = "myworld";
  5.         int i = 3;
  6.         printf("%10.*s", i, s);
  7.     }
a) myw
b) myworld(note:2 spaces before myworld)
c) myworld (note:2 spaces after myworld)
d) myw(note:6 spaces after myworld)
Answer: d
6. What is the difference between %e and %g?

a) %e output formatting depends on the argument and %g always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional.
b) %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument.
c) No differences
d) Depends on the standard
Answer: b
7. Escape sequences are prefixed with.

a) %
b) /
c) ”
d) None of the mentioned
Answer: d
8. What is the purpose of sprintf?

a) It prints the data into stdout
b) It writes the formatted data into a string
c) It writes the formatted data into a file
d) None of the mentioned
Answer: b
9. The syntax to print a % using printf statement can be done by.

a) %
b) %
c) ‘%’
d) %%
Answer: d
10. What does this statement printf(“%10s”, state); means?

a) 10 spaces before the string state is printed
b) Print empty spaces if the string state is less than 10 characters
c) Print the last 10 characters of the string
d) None of the mentioned
Answer: b
11. What are the Properties of first argument of a printf functions?

a) It is defined by user
b) It keeps the record of the types of arguments that will follow
c) There may no be first argument
d) None of the mentioned
Answer: b
12. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10, j = 2;
  5.         printf("%d\n", printf("%d %d ", i, j));
  6.     }
a) Compile time error
b) 10 2 4
c) 10 2 2
d) 10 2 5
Answer: d
13. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10, j = 3;
  5.         printf("%d %d %d", i, j);
  6.     }
a) Compile time error
b) 10 3
c) 10 3 some garbage value
d) Undefined behaviour
Answer: c
14. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10, j = 3, k = 3;
  5.         printf("%d %d ", i, j, k);
  6.     }
a) Compile time error
b) 10 3 3
c) 10 3
d) 10 3 somegarbage value
Answer: c
15. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char *s = "myworld";
  5.         int i = 9;
  6.         printf("%*s", i, s);
  7.     }
a) myworld
b) myworld(note: spaces to the left of myworld)
c) myworld (note:followed by two spaces after myworld)
d) Undefined
Answer: b
16. What is the output of this C code?
  1.     #include 
  2.     int main(int argc, char **argv)
  3.     {
  4.         char *s = "myworld";
  5.         int i = 3;
  6.         printf("%10.*s", i, s);
  7.     }
a) myw
b) myworld(note:2 spaces before myworld)
c) myworld (note:2 spaces after myworld)
d) myw(note:6 spaces after myworld)
Answer: d
17. What is the difference between %e and %g ?

a) %e output formatting depends on the argument and %g always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional.
b) %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument.
c) No differences
d) Depends on the standard
Answer: b

Related

CSS Multiple Choice Questions & Answers on Inheritance and Cascade for Freshers

1. Which of the following are different origins of style sheets? a) authorb) userc) user agentd) all of the mentioned Answer: d Explanation: Author: The author specifies style sheets for a source...

CSS Multiple Choice Questions & Answers on CSS Keyframes for Freshers

1. Which of the following CSS Property selects an animation defined in an @keyframes rule and applies it to the element? a) animationb) animation-namec) animation-elementd) none of the mentioned A...

Java Multiple Choice Questions & Answers on Exceptions Types for Freshers

1. Which of these is a super class of all exceptional type classes? a) Stringb) RuntimeExceptionsc) Throwabled) Cachable Answer: c Explanation: All the exception types are subclasses of the built...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item