Functions
August 29, 2024Database-Management-System
August 29, 2024Functions
Question 52 |
Consider the following function definition.
void greet (int n)
{
if (n>0)
{
printf(“hello”);
greet(n-1);
}
printf(“world”);
}
If you run greet(n) for some non-negative integer n, what would it print?
void greet (int n)
{
if (n>0)
{
printf(“hello”);
greet(n-1);
}
printf(“world”);
}
If you run greet(n) for some non-negative integer n, what would it print?
n times “hello”, followed by n + 1 times “world” | |
n times “hello”, followed by n times “world” | |
n times “helloworld” | |
n + 1 times “helloworld” | |
n times “helloworld”, followed by “world” |
Correct Answer: A