📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      Consider the following C code snippet:    

      #include     void printPattern(int n) {         if (n
      A 3 2 1 Correct Answer Incorrect Answer
      B 1 2 3 Correct Answer Incorrect Answer
      C 3 2 1 1 2 3 Correct Answer Incorrect Answer
      D 3 2 1 0 1 2 3 Correct Answer Incorrect Answer
      E 1 2 3 3 2 1 Correct Answer Incorrect Answer

      Solution

      Let's trace the execution: printPattern(3): n is 3. Prints "3 ". Calls printPattern(2):     n is 2. Prints "2 ".     Calls printPattern(1):         n is 1. Prints "1 ".         Calls printPattern(0):             n is 0. Base case, returns.         Prints "1 ". (After printPattern(0) returns)     Prints "2 ". (After printPattern(1) returns) Prints "3 ". (After printPattern(2) returns)     The sequence of prints is therefore "3 2 1 1 2 3".

      Practice Next
      ask-question