C While Looping MCQ
Q1. What will be the output of the following C code?
#includeint main() { while () printf("In while loop "); printf("After loop\n"); }
- In while loop after loop
- After loop
- Compile time error
- Infinite loop
Answer:- (C).
Explanations :None.
Explanations :None.
#includeint main() { do printf("In while loop "); while (0); printf("After loop\n"); }}
- In while loop
- In while loop)
- After loop
- Infinite loop
Answer:- (B).
Explanations :None.
Explanations :None.
#includeint main() { int i = 0; do { i++; printf("In while loop\n"); } while (i < 3); }
- In while loop
- Depends on the compiler
- loop
- Compile time error
Answer:- (A).
Explanations :None.
Explanations :None.
#includeint main() { int i = 0; do { i++; printf("in while loop\n"); } while (i < 3); }
- 2
- 3
- 4
- 1
Answer:- (B).
Explanations :None.
Explanations :None.
#includeint main() { int i = 0; while (i < 3) i++; printf("In while loop\n"); }
- 2
- 3
- 4
- 1
Answer:- (C).
Explanations :None
Explanations :None
#includevoid main() { int i = 2; do { printf("Hi"); } while (i < 2) }
- Compile time error
- Hi Hi
- Hi
- Varies
Answer:- (A).
Explanations :None
Explanations :None
#includevoid main() { int i = 0; while (++i) { printf("H"); } }
- H
- H is printed infinite times
- Compile time error
- Varies
Answer:- (B).
Explanations :None
Explanations :None
#includevoid main() { int i = 0; do { printf("Hello"); } while (i != 0); }
- Nothing
- H is printed infinite times
- Hello
- Run time error
Answer:- (C).
Explanations :None
Explanations :None
#includevoid main() { char *str = ""; do { printf("hello"); } while (str); }
- Nothing
- Run time error
- Varies
- Hello is printed infinite times
Answer:- (D).
Explanations :None
Explanations :None
#includevoid main() { int i = 0; while (i < 10) { i++; printf("hi\n"); while (i < 8) { i++; printf("hello\n"); } } }
- Hi is printed 8 times, hello 7 times and then hi 2 times
- Hi is printed 10 times, hello 7 times
- Hi is printed once, hello 7 times
- Hi is printed once, hello 7 times and then hi 2 times
Answer:- (D).
Explanations :None
Explanations :None
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.