Consider the following code (which does not do anything significant)int h(int p) { return p++;}int g(int x, int y) { int z; return h(y);}int f(int a, int b) { if(a % 3 == 0) { g(a, 2); } else { h(a); } return 10;}int main() { int m; scanf("%d", &m); if(m % 2 == 0) { f(m, 20); } else { g(20, m); } return 0; }How many functions can be active the same time, in the execution of the above program?
Question
Consider the following code (which does not do anything significant)int h(int p) { return p++;}int g(int x, int y) { int z; return h(y);}int f(int a, int b) { if(a % 3 == 0) { g(a, 2); } else { h(a); } return 10;}int main() { int m; scanf("%d", &m); if(m % 2 == 0) { f(m, 20); } else { g(20, m); } return 0; }How many functions can be active the same time, in the execution of the above program?
Solution 1
The maximum number of functions that can be active at the same time in the execution of the above program is 3. Here's the step-by-step explanation:
-
The
main()function is always active as it is the entry point of the program. -
If the input
mis even, themain()function calls thef()function. Insidef(), ifa(which ismin this case) is divisible by 3, it calls theg()function. -
Inside the
g()function, it calls theh()function.
So, in this scenario
Solution 2
The maximum number of functions that can be active at the same time in the execution of the above program is 3. This happens when the main function calls the function f (when m is even), and then function f calls function g (when a is not divisible by 3), and then function g calls function h. So, the functions main, f, g, and h can all be active at the same time. However, since each function returns before the next one is called, only one function is actually executing at any given time.
Similar Questions
Consider the C program shown below -int sumOdd(int *a, int n){ if(n <= 0) return 0; else if (*a % 2 != 0) return *a + sumOdd (a + 1, n - 1); return sumOdd (a + 1, n - 1);}int main(){ int a[] = {1,2, 3, 4, 5 ,6}; printf("%d\n", sumOdd(a, 6)); return 0;}The output of this program is -912158
Select the correct answerOutput by the below given code is:#include<stdio.h>int Function(int x, int *P1, int **P2) { int y, z; **P2 += 2; z = **P2; *P1 += 3; y = *P1; x += 4; return x + y + z; } int main() { int c, *b, **a; c = 10; b = &c; a = &b; printf("%d ", Function(c, b, a)); return 0;}Options40414344
n the following code,int f(int *a) { *a = 20;}int main() { int m = 30; f(&m);}a.The parameter passing is "pass by address", and the "address of m" is passedb.Parameter passing is by value, the value passed is "address of m", and copied into the argument *a c.Parameter passing is by value, the value passed is "m", and copied into the argument a d.Parameter passing is by value, the value passed is "address of m", and copied into the argument ae.The parameter passing is "pass by reference" and variable a is a reference to variable m.
What is the output of the following program?#include<stdio.h> int main() { int a[5] = {2, 3}; printf("%d, %d, %d", a[2], a[3], a[4]); return 0; }Select one:Compilation error2, 3, 30, 0, 03, 2, 2
Output of following C program is:-int fun(int x) { int k = 1; if(x <= 1) return 1; k = fun(x-2)* fun(x - 1); return k;} void main() { printf("%d",fun(4));}a.1b.Segmentation faultc.10d.6
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.