Professional Documents
Culture Documents
Assignment 8 July 2022 Solution
Assignment 8 July 2022 Solution
a) 70
b) Garbage value
c) Compilation error
d) None
Solution: (b) The function f() is called from the main. After printing ‘1’, foo() will be
called, and ‘2’ will be printed. This is an example of a nested function.
a) Choice1
b) CChoice1
Assignment 8 July 2022 Solution
c) DefaultChoice1
d) CChoice1Choice2
Solution: (b)
Solution: The first printf statement inside the switch prints ‘C’ and returns 1 (i.e. the
number of elements/characters inside printf) to the switch i.e. switch(1), therefore the
case 1 is invoked and Choice1 is printed. So, the whole answer is CChoice1.
a) Compilation error
b) 0, 1, 2 …….., 127
c) 0, 1, 2, …….., 127, -128, -127,…infinite loop
d) 1, 2, 3…….,127
Solution: (c)
Because the character data type range varies from -128 to 127, after reaching the value of
127, the value of x changes to -128 by incrementing and therefore the loop runs all over
again, and the process continues.
return 0;
}
a) 55
b) 45
c) 66
d) 10
Solution: (a) The program finds the sum of the integer numbers till 10. Thus the output is
55.
return 1;
}
The function above has a flaw that may result in a serious error during some
invocations.
Which one of the following describes the deficiency illustrated above?
(a) For some values of n, the environment will almost certainly exhaust its stack
space before the calculation completes.
(b) An error in the algorithm causes unbounded recursion for all values of n.
(c) A break statement should be inserted after each case. Fall-through is not
desirable here.
(d) The fibonacci() function includes calls to itself. This is not directly supported by
Standard C due to its unreliability.
Solution (a) For some values of n, the environment will almost certainly exhaust its stack
space before the calculation completes.
The function calls itself. So it's an example of recursion. As there is no proper terminating
condition for the function, for a large value of n, it will exhaust the storage space (stack),
which will stop the execution without a final result.
int main()
{
float result, age[] = { 23.4, 55, 22.6, 3, 40.5, 18 };
result = func(age);
printf("Result is=%0.2f", result);
return 0;
}
Ans: 27.08
Assignment 8 July 2022 Solution
Solution: The code essentially calculates the average of the provided numbers.