Function in C MCQs Exercise II

Ques 1 Function


Consider the following function f is

int f(int n)
{
    if(n<=0)
        return 1;
    else if(n%2==0) return f(n/2);
    else return f(3n-1);
}

Assume that arbitrary large integers can be passed as a parameter to the following to the function,consider the following statements.

i) The function f terminates for finitly many different values of n>=1.
ii) The Function f terminates for infintely many different values of n>=1.
iii) The function f terminates for finitly many different values of n>=1.
iv) The function f does not terminate for infinitly many different values of n>=1.

Which of the following options is true of the above?

A (i) and (iii)
B (i) and (iv)
C (ii) and (iii)
D (ii) and (iv)

Ques 2 Function


The keyword is used to transfer control from a function back to the calling function is

A function's name
B return
C parameters
D None of these

Ques 3 Function


Consider the following C-program
double foo(double);/*Line 1*/
int main( ){
    double da,db;
    //input da
    db=foo(da)
}
double foo(double a){
    return a;
}

The above code complied without any error or warning.if line is deleted then the above code will be see

A No compile warning or error
B Some compiler-warning not leading tountended result
C Some compiler warning not leading to unitended result eventually leading to unitended result
D Compiler Error

Ques 4 Function


Consider the following C-program
void foo(int n,int sum){
    int k=0,j=0;
    if(n==0) return 0;
    k=n%10;
    j=n/10;
    sum=sum+k;
    foo(j,sum);
    printf("%d",k);
}
int main( ){
    int a=2048,sum=0;
    foo(a,sum);
    printf("%d\t",sum);
}

A 8 4 0 2 14
B 8 4 0 2 0
C 2 0 4 8 14
D 2 0 4 8 0