C MCQ Questions and Answers on Functions and Pointers 2

Image
C MCQ Questions and Answers

Study C MCQ Questions and Answers on Functions and Pointers. Questions are on Recursion, Pass by Value and Pass By Reference. Attend C technical interviews easily after reading these Multiple Choice Questions.

Go through C Theory Notes on Functions before reading questions.



1) What is the limit for number of functions in a C Program.?
A) 16
B) 31
C) 32
D) None of the above
Answer [=]
D
Explanation:

Yes. There is no limit on the number of functions in a C Program.

2) Every C Program should contain which function.?
A) printf()
B) show()
C) scanf()
D) main()
Answer [=]
D
Explanation:

main() is a compulsory function with or without returning anything.

void main(){}

int main(){return 0;}

3) What is the minimum number of functions to be present in a C Program.?
A) 1
B) 2
C) 3
D) 4
Answer [=]
A
Explanation:

At least there will be one function which is main() function.

4) What is the output of C Program with functions.?
static void show();

int main()
{
    printf("ROCKET ");
    show();
    return 0;
}

static void show()
{
    printf("STATIC");
}
A) ROCKET
B) ROCKET STATIC
C) STATIC ROCKET
D) Compiler error
Answer [=]
B
Explanation:

Yes. A function can be static. Remember that a static variable or function has only FILE scope. You can use this function outside of the defined file even with extern static void show() prototype declaration.

5) What is the maximum number of statements that can present in a C function.?
A) 64
B) 128
C) 256
D) None of the above
Answer [=]
D
Explanation:

There is no limit on the number of statements that can present in a C Function.

6) What characters are allowed in a C function name identifier.?
A) Alphabets, Numbers, %, $, _
B) Alphabets, Numbers, Underscore ( _ )
C) Alphabets, Numbers, dollar $
D) Alphabets, Numbers, %
Answer [=]
B
Explanation:

Remember that a C function name can not start with a number but it can contain contain numbers after 1st character is either an Underscore ( _ ) or an Alphabet.

7) What is the output of C Program with functions and pointers.?
int main()
{
    int b=25;
    //b memory location=1234;
    int *p = b;
    printf("%d %d", b, p);

    return 0;
}
A) 25 1234
B) 25 0
C) 25 25
D) Compiler error
Answer [=]
C
Explanation:

Integer Pointer *p copied the value of b to a new memory location. Its is same as int p= b;. Only p=&b points to the same memory of b.



8) What is the output of C Program with functions and pointers.?
int main()
{
    int b=25;
    //b memory location=1234;
    int *p;
    p=&b;
    printf("%d %d %d", &b, p);
    return 0;
}
A) 25 25
B) 1234 1234
C) 25 1234
D) 1234 25
Answer [=]
B
Explanation:

Integer pointer is declared by int *p. p=&b makes pointer P to point the address of b. So &b and p hold only address.

9) What do you call STAR * and Ampersand & in a c program context.?
int a=10, *p;
p = &a;
printf("%d %d", a, *p);
A) * = ADDRESS OF operator, & = VALUE AT operator
B) * = ADDRESS OF operator, & = ADDRESS OF operator
C) * = VALUE AT operator, & = ADDRESS OF operator
D) * = VALUE AT operator, & = VALUE AT operator
Answer [=]
C
Explanation:

&b gives ADDRESS OF b. *p gives VALUE AT memory location of b.

10) What is the output of C Program with functions.?
#include 
int sum(int,int);
int main()
{
    int a=5, b=10, mysum;
    mysum = sum(a,b);
    printf("SUM=%d ", mysum);
    printf("SUM=%d", sum(10,20));
    return 0;
}
int sum(int i, int j)
{
    return (i+j);
}
A) SUM=15 SUM=30
B) SUM=30 SUM=15
C) SUM=15 SUM=15
D) SUM=30 SUM=30
Answer [=]
A
Explanation:

You can call a function sum(10,20) inside another function printf directly.

11) Arguments passed to a function in C language are called ___ arguments.
A) Formal arguments
B) Actual Arguments
C) Definite Arguments
D) Ideal Arguments
Answer [=]
B
12) Arguments received by a function in C language are called ___ arguments.
A) Definite arguments
B) Formal arguments
C) Actual arguments
D) Ideal arguments
Answer [=]
B
13) Choose a corrects statement about C language function arguments.
A) Number of arguments should be same when sending and receiving
B) Type of each argument should match exactly 
C) Order of each argument should be same
D) All the above
Answer [=]
D
Explanation:

20.0 is float. But char j is Character type. So, it is a mismatch. Here exactly two arguments are passed and two arguments are received.

int main()
{
    sum(10, 20.0);
    return 0;
}
int sum(int i, char j)
{
    return 10;
}
14) What is the output of C program with functions.?
int main()
{
    printf("funny=%d" , funny());
    return 0;
}
funny()
{
   
}
A) funny=
B) funny=1
C) funny=0
D) Compiler error
Answer [=]
C
Explanation:

By default, a return 0; is added at the end of any function if not explicitly specified.



15) What is the output of C Program with functions.?
void funny2();
int main()
{
    printf("funny2=%d" , funny2());
    return 0;
}
void funny2()
{

}
A) funny2=
B) funny2=0
C) funny2=1
D) Compiler error
Answer [=]
D
Explanation:

void function does not return anything.

16) Choose a correct statement with C Functions.
A) A function can call any other function any number of times
B) You can write any function in any order in a multi function C File.
C) You can refer to or call any function using a Pointer also.
D) All the above
Answer [=]
D
17) Choose a non Library C function below.
A) printf()
B) scanf()
C) fprintf()
D) printf2()
Answer [=]
D
Explanation:

fprintf is used along with files. There is no library function PRINTF2().

18) What is the default return value of a C function if not specified explicitly.?
A) -1
B) 0
C) 1
D) None of the above
Answer [=]
C
Explanation:
int funny()
{
//return 0; is added by compiler.
}
19) What do you call this C Function calling itself.?
int funny2()
{
    funny2(num);
}
A) Indefinite Function
B) Definite Function
C) Cursive Function
D) Recursive Function
Answer [=]
D
Explanation:

This recursive function hangs the CPU as there is no come out condition with IF.

20) What is the output of C Program with functions.?
int bunny(int,int);
int main()
{
    int a, b;
    a = bunny(5, 10);
    b = bunny(10, 5);
    printf("%d %d", a, b);
    return 0;
}
int bunny(int i, int j)
{
    return (i, j);
}
A) 5 10
B) 10 5
C) 5 5
D) Compiler error
Answer [=]
B
Explanation:

Do not try to put the same return (a,b). It is a bad practice to return 2 values at a time. You can return only one value. Value right side value return j works every time.