MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What will be the values return by the function ‘f’ in the following code?#include<stdio.h>void f(int n, int sum) { int k = 0, j = 0; if (n == 0) return; k = n % 10; j = n / 10; sum = sum + k; f (j, sum); printf ("%d, “, k); } int main () { int a = 2045, sum = 0; f (a, sum); printf ("%d", sum); }
A
5, 4, 0, 2, 12
B
5, 3, 0, 2, 0
C
2, 0, 4, 5, 14
D
2, 0, 4, 5, 0
Explanation: 

Detailed explanation-1: -Function f() returns an array. So var a=f() assigns an array in a . Now each array element is itself a function. So if you access any array element in the array a it will simply access the function definition but will not execute it.

Detailed explanation-2: -To return a value from a function, you must include a return statement, followed by the value to be returned, before the function’s end statement. If you do not include a return statement or if you do not specify a value after the keyword return, the value returned by the function is unpredictable.

Detailed explanation-3: -In general, a function takes arguments (if any), performs some operations, and returns a value (or object). The value that a function returns to the caller is generally known as the function’s return value. All Python functions have a return value, either explicit or implicit.

Detailed explanation-4: -A function that returns a value is called a value-returning function. A function is value-returning if the return type is anything other than void . A value-returning function must return a value of that type (using a return statement), otherwise undefined behavior will result. Related content.

There is 1 question to complete.