C Function Basics MCQs: 10 Solved Questions on Prototypes, Calls and Parameters

Solve 10 C function MCQs, then use the explanations to separate declarations, definitions, copied arguments, return values, static locals and scope.

KnowledgeGate Team

Exam prep & CS education

Updated 29 Aug 20267 min read

Function questions look small, but confusing a declaration, definition, call, copied argument, return value, local name or persistent static variable can change the answer. Solve these 10 questions before reading each explanation, then use every miss to identify the boundary you crossed. The set belongs to the Coding and DSA category.

Declaration, definition and linkage are three different jobs

int add(int a, int b);

int add(int a, int b) {
    return a + b;
}

int main(void) {
    int result = add(7, 5);
    return result == 12 ? 0 : 1;
}

The first line is the declaration or prototype. The add body is the definition. In main, the call makes result equal 7 + 5 = 12. C has no function or def keyword. The return type begins either form.

Q1

User defined functions in C are written using the keyword _____.

  • (0) #define

  • (1) function keyword

  • (2) def keyword

  • (3) None of these

Answer: option 3, None of these. A C function begins with its return type, then its name, parameters and, in a definition, its body. None of the first three choices is a function-definition keyword.

Q2

What is a function prototype used for ?

  • (0) To define the return type of a function

  • (1) To declare the function before its definition

  • (2) To specify the function's parameters

  • (3) To document the function's purpose

Answer: option 1, To declare the function before its definition. int add(int, int); gives the compiler return type int, name add and two int parameter types, but no body. The prototype declares that contract before a later definition.

Q3

The default storage class for functions in ‘C’ language is:

  • (0) Static

  • (1) Register

  • (2) Extern

  • (3) Auto

Answer: option 2, Extern. In this question, Extern is the best choice because a function declared at file scope has external linkage unless it is declared static, which gives internal linkage. auto and register cannot be used for function declarations.

Arguments enter by value and results leave through return

Q4

What happens when a variable is passed by value to a function in C?

  • (0) The function receives a copy of the variable's value

  • (1) The function alters the original variable directly

  • (2) The function accesses the memory location of the variable

  • (3) The function gets a reference to the original variable

Answer: option 0, The function receives a copy of the variable's value. With int y = 20; fun(y);, the call copies 20 into x. Assigning x = 30 changes only that copy. Later, printf("%d", y) still prints 20.

Q5

In C language

  • (0) parameters are always passed by values

  • (1) parameters are always passed by reference

  • (2) non-pointer variables are passed by value and pointers are passed by reference

  • (3) parameters are always passed by value result

Answer: option 0, parameters are always passed by values. In int n = 7; int *p = &n; use(p);, the pointer value is copied into the parameter. Both pointers designate n, so *parameter = 9 changes n to 9. This remains pass by value.

Q6

The value obtained in the function is given back to main by using __________ keyword.

  • (0) Static

  • (1) Return

  • (2) New

  • (3) Volatile

Answer: option 1, Return. In int square(int n) { return n * n; }, square(6) gives the caller 6 * 6 = 36. It prints nothing unless the caller prints or otherwise uses 36. The option is capitalised, but the C keyword is lowercase return.

A local swap is not a caller-side swap

Q7

Consider the following C function

void swap ( int x, int y )
{
    int tmp;
    tmp = x;
    x= y;
    y = tmp;
}

In order to exchange the values of two variables a and b:

  • (0) Call swap (a, b)

  • (1) Call swap (&a, &b)

  • (2) swap(a, b) cannot be used as it does not return any value

  • (3) swap(a, b) cannot be used as the parameters passed by value

Answer: option 3, swap(a, b) cannot be used as the parameters passed by value. Let the caller hold a = 4 and b = 9. The call starts the callee with copies x = 4, y = 9. Its assignments produce tmp = 4, then x = 9, then y = 4. On return, the caller still has a = 4, b = 9.

Option 1 does not fix this function. swap(&a, &b) supplies pointers, but the declared parameters are int x, int y. A matching definition is void swap(int *x, int *y), with int tmp = *x; *x = *y; *y = tmp;. Now swap(&a, &b) leaves the caller with a = 9, b = 4.

Two Q7 swap traces: passing ints by value leaves a and b unchanged, while the pointer version swaps them to 9 and 4.

Static locals retain state across calls

Q8

The following program

main()
{
    inc(); inc(); inc();
}
inc()
{
    static int x;
    printf("%d", ++x);
}
  • (0) prints 012

  • (1) prints 123

  • (2) prints 3 consecutive, but unpredictable numbers

  • (3) prints 111

Answer: option 1, prints 123. Static x receives one-time zero initialisation. The three ++x operations produce and print 1, 2 and 3. With no spaces, the output is 123.

The displayed code uses implicit return types and omits stdio.h. Modern compile-ready C would include the header and declare both functions explicitly: #include <stdio.h>, void inc(void) and int main(void).

Q9

What will be the output of the following program?

int f (int x)
{
    static int y;
    y += x;
    return (y);
}
main ( )
{
    int a, i;
    for (i = 0; i < 6; i++)
        a = f (i);
    printf ("%d", a);
}
  • (0) 6

  • (1) 8

  • (2) 10

  • (3) 15

Answer: option 3, 15. Static y starts at 0. The calls return f(0) = 0, f(1) = 1, f(2) = 3, f(3) = 6, f(4) = 10, and f(5) = 15. Since a is overwritten each time, it finally holds 15.

With ordinary int y = 0; inside f, every call would create a fresh y. The returns would be 0, 1, 2, 3, 4, 5, and the final output would be 5, not 15.

Scope decides which same-named object a function uses

Q10

What is the output of the following program?

#include <stdio.h>
int tmp=20;
main( )
{
    printf("%d ",tmp);
    func( );
    printf("%d ",tmp);
}
func( )
{
    static int tmp=10;
    printf("%d ",tmp);
}
  • (0) 20 10 10

  • (1) 20 10 20

  • (2) 20 20 20

  • (3) 10 10 10

Answer: option 1, 20 10 20. main first resolves tmp to the file-scope object and prints 20. In func, block-scope static int tmp = 10 hides it and prints 10. Back in main, the unchanged file-scope object prints 20.

Scope and storage duration differ. The local tmp has block scope and static storage duration. The global tmp has file scope and static storage duration. Equal spelling does not join them. The displayed code uses legacy implicit return types. Modern runnable C would retain #include <stdio.h> and add void func(void);, int main(void) and a void func(void) definition. Those declarations do not change the trace.

Each question tests a different function boundary

Question

Answer

Boundary tested

Q1

Option 3

C has no function-definition keyword

Q2

Option 1

A prototype declares before definition

Q3

Option 2

External linkage is the default

Q4

Option 0

The parameter receives a copy

Q5

Option 0

C passes every argument value by value

Q6

Option 1

return sends a value to the caller

Q7

Option 3

Swapping copied integers cannot alter the caller

Q8

Option 1

Static x prints 1, then 2, then 3

Q9

Option 3

Persistent y reaches 15

Q10

Option 1

Scope selects 20, then 10, then 20

Use misses as diagnoses. Q1 to Q3 test declaration syntax and linkage. Q4, Q5 and Q7 test copied values. Q8 and Q9 test persistent static storage. Q10 tests whether you check scope before matching names.

Keep an error log and attempt missed questions again after a gap. Use Why PYQs Beat Buying Another Question Bank for a repetition method that turns wrong answers into revision targets.

Short version and the next practice step

  • A declaration tells the compiler the interface.

  • A definition supplies the body.

  • A call creates parameters from argument values.

  • return sends control and possibly a value back.

  • Pointer arguments are pointer values copied by value.

  • Static locals remember, while ordinary automatic locals are created afresh on each call.

Redo Q2, Q7, Q9 and Q10 without their explanations. For Q7, write the four caller values before and after the call. For Q9, write 0, 1, 3, 6, 10, 15. For Q10, label each tmp as file-scope or block-scope. Then check the compact answer table.

Continue with Data Structures MCQs for more programming practice. If question formats get mixed up, read MCQ, MSQ or NAT? GATE Question Types Explained.

For more C concepts and MCQs, use the C Language course. For broader C, C++, Java, Python and competitive-coding study, use Coding for Placements.