C Programming Questions and Answers on While Loops for Freshers

1. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         while ()
  5.             printf("In while loop ");
  6.         printf("After loop\n");
  7.     }
a) In while loop after loop
b) After loop
c) Compile time error
d) Infinite loop
Answer: c
2. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         do
  5.             printf("In while loop ");
  6.         while (0);
  7.             printf("After loop\n");
  8.     }
a) In while loop
b) In while loop
after loop
c) After loop
d) Infinite loop
Answer: b
3. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         do {
  6.             i++;
  7.             printf("In while loop\n");
  8.         } while (i < 3);
  9.     }
a) In while loop
In while loop
In while loop
b) In while loop
In while loop
c) Depends on the compiler
d) Compile time error
Answer: a
4. How many times i value is checked in the below code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         do {
  6.             i++;
  7.             printf("in while loop\n");
  8.         } while (i < 3);
  9.     }
a) 2
b) 3
c) 4
d) 1
Answer: b
5. How many times i value is checked in the below code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         while (i < 3)
  6.             i++;
  7.         printf("In while loop\n");
  8.     }
a) 2
b) 3
c) 4
d) 1
Answer: c
6. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 2;
  5.         do
  6.         {
  7.             printf("Hi");
  8.         } while (i < 2)
  9.     }
a) Compile time error
b) Hi Hi
c) Hi
d) Varies
Answer: a
7. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         while (++i)
  6.         {
  7.             printf("H");
  8.         }
  9.     }
a) H
b) H is printed infinite times
c) Compile time error
d) Varies
Answer: b
8. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         do
  6.         {
  7.             printf("Hello");
  8.         } while (i != 0);
  9.     }
a) Nothing
b) H is printed infinite times
c) Hello
d) Run time error
Answer: c
9. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *str = "";
  5.         do
  6.         {
  7.             printf("hello");
  8.         } while (str);
  9.     }
a) Nothing
b) Run time error
c) Varies
d) Hello is printed infinite times
Answer: d
10. What is the output of this C code?
  1. #include 
  2. void main()
  3. {
  4.     int i = 0;
  5.     while (i < 10)
  6.     {
  7.         i++;
  8.         printf("hi\n");
  9.         while (i < 8) 
  10.         {
  11.             i++;
  12.             printf("hello\n");
  13.         }
  14.     }
  15. }
a) Hi is printed 8 times, hello 7 times and then hi 2 times
b) Hi is printed 10 times, hello 7 times
c) Hi is printed once, hello 7 times
d) Hi is printed once, hello 7 times and then hi 2 times
Answer: d
11. Example of iteration in C.

a) for
b) while
c) do-while
d) all of the mentioned
Answer: d
12. Number of times while loop condition is tested is, i is initialized to 0 in both case.

  1. while (i < n)
  2.          i++;
  3.     ————-
  4.     do
  5.          i++;
  6.     while (i <= n);
a) n, n
b) n, n+1
c) n+1, n
d) n+1, n+1
Answer: d
13. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         while (i = 0)
  6.             printf("True\n");
  7.         printf("False\n");
  8.     }
a) True (infinite time)
b) True (1 time) False
c) False
d) Compiler dependent
Answer: c
14. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0, j = 0;
  5.         while (i < 5, j < 10)
  6.         {
  7.             i++;
  8.             j++;
  9.         }
  10.         printf("%d, %d\n", i, j);
  11.     }
a) 5, 5
b) 5, 10
c) 10, 10
d) Syntax error
Answer: c
15. Which loop is most suitable to first perform the operation and then test the condition?

a) for loop
b) while loop
c) do-while loop
d) none of the mentioned
Answer: c

Related

C# Questions & Answers on Recursion for Freshers

1. What is Recursion in CSharp defined as? a) Recursion is another form of classb) Recursion is another process of defining a method that calls other methods repeatedlyc) Recursion is a process of ...

C# Questions & Answers on Introduction of Overloaded Operators for Freshers

1. Which of the following keyword is used to overload user defined types by defining static member functions? a) opb) opoverloadc) operatord) operatoroverload Answer: c 2. Which of following stat...

C# Questions & Answers on Interfaces Implementation for Freshers

1. Correct statement about c#.NET code snippet given below is? interface a1 { void f1(); int f2(); } class a :a1 { void f1() { } int a1.f2() { } ...

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