Consider the following C code:#include<stdio.h>
int temp = 0;
int fun(int x, int y) {
int z; temp++;
if (y == 3) return (x*x*x);
else {
z = fun(x, y/3);
return (z*z*z);
}
}
int main() {
fun(4, 81);
printf("%d", temp);
}What will be the output of the code?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. 4
Explanation
Calls are made with y = 81, 27, 9, 3, and each call increments temp, so temp = 4.More Programming Languages and Computer Graphics questions
- Match List I with List IIList I List II (A) HTML (I) Allows for dynamic and interactive web pages. (B) DHTML (II) Defines the structure of…
- Arrange the following steps of file handling in C in the correct order: (A) Close the file (B) Read from or write to the file (C) Open the…
- What will be the output of the following C code?#include<stdio.h> void main() { int arr[5] = {10,20,30,40,50}; int *p = (int*)(&arr + 1); p…
- Find the output of the following code:#include<stdio.h> void main() { int arr[] = {1, 2, 3, 4, 5}; int *p = arr; printf("%d", *p++); printf…
- Consider a triangle PQR with coordinates P(0,0), Q(2,2) and R(10,4). If this triangle is to be magnified to four times its size while keepi…
- Which of the following statements is TRUE?