最后,您会看到调用myPrint
它们发生的顺序.
这是查看每次递归调用期间发生的事情的一种方法.
myPrint(4) printf("%d", n/2) // Prints 2 because 4/2 = 2 myPrint(n - 1) // Calls myPrint(3) printf("%d", n/2) // Prints 1 because 3/2 = 1 myPrint(n - 1) // Calls myPrint(2) printf("%d", n/2) // Prints 1 because 2/2 = 1 myPrint(n - 1) // Calls myPrint(1) printf("%d", n/2) // Prints 0 because 1/2 = 0 myPrint(n - 1) // Calls myPrint(0) printf("%d", n/2) // Prints 0 because 0/2 = 0 // Does not execute if statement printf("%d", n); // Prints 0 because n = 0 at this call printf("%d", n); // Prints 1 because n = 1 at this call printf("%d", n); // Prints 2 because n = 2 at this call printf("%d", n); // Prints 3 because n = 3 at this call printf("%d", n); // Prints 4 because n = 4 at this call