Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 4 MCQs Functions

CAP1008 — C Programming 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 function definition Easy

    Which of the following is the correct syntax for a function definition in C?

  2. Question 2 of 60 function definition Easy

    What are the two main parts of a function definition in C?

  3. Question 3 of 60 predefined functions and user defined functions Easy

    Functions like printf() and scanf() are examples of which type of functions?

  4. Question 4 of 60 predefined functions and user defined functions Easy

    A function written by the programmer to perform a specific task is called a:

  5. Question 5 of 60 predefined functions and user defined functions Easy

    Which header file must be included to use the sqrt() function in C?

  6. Question 6 of 60 scope rules - local and global scope Easy

    A variable declared inside a function is known as a:

  7. Question 7 of 60 scope rules - local and global scope Easy

    A global variable in C is accessible:

  8. Question 8 of 60 scope rules - local and global scope Easy

    Where should a global variable be declared in a C program?

  9. Question 9 of 60 basics of pointers: pointer declaration Easy

    Which of the following correctly declares a pointer to an integer?

  10. Question 10 of 60 basics of pointers: pointer declaration Easy

    What does a pointer variable store?

  11. Question 11 of 60 initialization Easy

    Which operator is used to get the address of a variable when initializing a pointer?

  12. Question 12 of 60 initialization Easy

    Given int x = 5; int *p = &x;, what does p hold?

  13. Question 13 of 60 accessing values using pointers Easy

    Which operator is used to access the value stored at the address a pointer points to?

  14. Question 14 of 60 accessing values using pointers Easy

    If int x = 10; int *p = &x;, what is the value of *p?

  15. Question 15 of 60 passing arguments by value and passing arguments by address Easy

    In call by value, changes made to the parameters inside the function:

  16. Question 16 of 60 passing arguments by value and passing arguments by address Easy

    Which method allows a function to modify the caller's original variables?

  17. Question 17 of 60 passing arguments by value and passing arguments by address Easy

    When passing arguments by address, what is actually passed to the function?

  18. Question 18 of 60 recursion Easy

    Recursion is a process in which a function:

  19. Question 19 of 60 recursion Easy

    What is essential in every recursive function to prevent infinite calls?

  20. Question 20 of 60 library functions Easy

    Which of the following is a standard string library function in C?

  21. Question 21 of 60 function definition Medium

    Consider the following function definition:

    C
    int compute(int a, int b) {
        return a * b + a;
    }



    What value does compute(3, 4) return?

  22. Question 22 of 60 function definition Medium

    Which of the following correctly describes the components of a C function definition?

  23. Question 23 of 60 predefined functions and user defined functions Medium

    Which statement best distinguishes a user-defined function from a predefined (library) function in C?

  24. Question 24 of 60 predefined functions and user defined functions Medium

    To use the pow() function in a C program, which header file must be included?

  25. Question 25 of 60 scope rules - local and global scope Medium

    What is the output of the following program?

    C
    #include <stdio.h>
    int x = 10;
    void show() {
        int x = 20;
        printf("%d", x);
    }
    int main() {
        show();
        return 0;
    }

  26. Question 26 of 60 scope rules - local and global scope Medium

    Which statement about local and global scope in C is correct?

  27. Question 27 of 60 scope rules - local and global scope Medium

    What is the output of this program?

    C
    #include <stdio.h>
    int count = 5;
    void update() {
        count = count + 10;
    }
    int main() {
        update();
        printf("%d", count);
        return 0;
    }

  28. Question 28 of 60 basics of pointers: pointer declaration, initialization, accessing values using pointers Medium

    Given the declarations int a = 25; int *p = &a;, what does *p evaluate to?

  29. Question 29 of 60 basics of pointers: pointer declaration, initialization, accessing values using pointers Medium

    What is the output of the following code?

    C
    #include <stdio.h>
    int main() {
        int x = 7;
        int *p = &x;
        *p = *p + 3;
        printf("%d", x);
        return 0;
    }

  30. Question 30 of 60 basics of pointers: pointer declaration, initialization, accessing values using pointers Medium

    Which of the following correctly declares a pointer to an integer and initializes it with the address of variable n?

  31. Question 31 of 60 passing arguments by value and passing arguments by address Medium

    What is the output of the following program?

    C
    #include <stdio.h>
    void change(int a) {
        a = a + 5;
    }
    int main() {
        int x = 10;
        change(x);
        printf("%d", x);
        return 0;
    }

  32. Question 32 of 60 passing arguments by value and passing arguments by address Medium

    What is the output of the following program?

    C
    #include <stdio.h>
    void change(int *a) {
        *a = *a + 5;
    }
    int main() {
        int x = 10;
        change(&x);
        printf("%d", x);
        return 0;
    }

  33. Question 33 of 60 passing arguments by value and passing arguments by address Medium

    Which technique should be used to write a swap function that successfully exchanges the values of two variables from the caller?

  34. Question 34 of 60 recursion Medium

    What does the following recursive function return for fun(4)?

    C
    int fun(int n) {
        if (n == 0) return 0;
        return n + fun(n - 1);
    }

  35. Question 35 of 60 recursion Medium

    What is the output of fact(5) for the following function?

    C
    int fact(int n) {
        if (n <= 1) return 1;
        return n * fact(n - 1);
    }

  36. Question 36 of 60 recursion Medium

    What happens if a recursive function does not have a proper base case?

  37. Question 37 of 60 recursion Medium

    For the recursive function below, how many times is display called (including the initial call) when invoked as display(3)?

    C
    void display(int n) {
        if (n == 0) return;
        printf("%d", n);
        display(n - 1);
    }

  38. Question 38 of 60 library functions Medium

    Which library function is used to determine the length of a string (excluding the null terminator) in C?

  39. Question 39 of 60 library functions Medium

    What is the return value of sqrt(16.0) from the math library?

  40. Question 40 of 60 library functions Medium

    Which library function converts a string such as "123" into its integer equivalent 123?

  41. Question 41 of 60 recursion Hard

    Consider the following function:

    C
    int f(int n) {
        if (n == 0) return 0;
        return n + f(n - 1);
    }



    What is the maximum recursion depth (number of active stack frames including the initial call) when f(5) is invoked?

  42. Question 42 of 60 passing arguments by value and passing arguments by address Hard

    What does the following program print?

    C
    #include <stdio.h>
    void swap(int *a, int b) {
        int t = *a; *a = b; b = t;
    }
    int main() {
        int x = 3, y = 7;
        swap(&x, y);
        printf("%d %d", x, y);
    }

  43. Question 43 of 60 scope rules - local and global scope Hard

    What is the output of this program?

    C
    #include <stdio.h>
    int x = 10;
    void f() { x += 5; }
    int main() {
        int x = 20;
        f();
        { int x = 30; printf("%d ", x); }
        printf("%d", x);
    }

  44. Question 44 of 60 basics of pointers: pointer declaration, initialization, accessing values using pointers Hard

    Given int a[] = {10, 20, 30, 40}; int *p = a + 1;, what is the value of *(p + 1) + *(a + 2)?

  45. Question 45 of 60 recursion Hard

    What does mystery(4) return?

    C
    int mystery(int n) {
        if (n <= 1) return 1;
        return mystery(n - 1) + mystery(n - 2);
    }

  46. Question 46 of 60 basics of pointers: pointer declaration, initialization, accessing values using pointers Hard

    What is printed by the following code?

    C
    #include <stdio.h>
    int main() {
        int x = 5;
        int *p = &x;
        int **q = &p;
        **q = **q + 10;
        printf("%d", x);
    }

  47. Question 47 of 60 scope rules - local and global scope Hard

    What is the output of this program using a static local variable?

    C
    #include <stdio.h>
    int counter() {
        static int c = 0;
        c++;
        return c;
    }
    int main() {
        printf("%d%d%d", counter(), counter(), counter());
    }

  48. Question 48 of 60 passing arguments by value and passing arguments by address Hard

    What is the output?

    C
    #include <stdio.h>
    void change(int *p) {
        p = p + 1;
        *p = 99;
    }
    int main() {
        int a[3] = {1, 2, 3};
        change(a);
        printf("%d %d %d", a[0], a[1], a[2]);
    }

  49. Question 49 of 60 library functions Hard

    What does the following code print?

    C
    #include <stdio.h>
    #include <string.h>
    int main() {
        char s[20] = "Hello";
        strcat(s, "World");
        printf("%zu", strlen(s));
    }

  50. Question 50 of 60 recursion Hard

    For the function below, what is f(6)?

    C
    int f(int n) {
        if (n == 0) return 1;
        if (n % 2 == 0) return f(n - 1);
        return 2 * f(n - 1);
    }

  51. Question 51 of 60 function definition Hard

    In C, what happens if a function is called before any declaration or definition is visible, and it returns a double, but is implicitly assumed to return int?

  52. Question 52 of 60 predefined functions and user defined functions Hard

    Which statement best distinguishes a predefined (library) function from a user-defined function in C?

  53. Question 53 of 60 basics of pointers: pointer declaration, initialization, accessing values using pointers Hard

    Which declaration correctly defines p as a pointer to a function that takes an int and returns an int?

  54. Question 54 of 60 recursion Hard

    How many times is f called in total (including the initial call) when f(3) runs?

    C
    void f(int n) {
        if (n <= 0) return;
        f(n - 1);
        f(n - 1);
    }

  55. Question 55 of 60 passing arguments by value and passing arguments by address Hard

    What is the output?

    C
    #include <stdio.h>
    void modify(int *pp) {
        static int val = 100;
        pp = &val;
        *pp = 200;
    }
    int main() {
        int a = 5;
        int *p = &a;
        modify(p);
        printf("%d", *p);
    }

  56. Question 56 of 60 scope rules - local and global scope Hard

    What does this program output?

    C
    #include <stdio.h>
    int x = 1;
    int f() { return x; }
    int main() {
        int x = 2;
        { extern int x; printf("%d ", x); }
        printf("%d", f());
    }

  57. Question 57 of 60 library functions Hard

    What is printed?

    C
    #include <stdio.h>
    #include <stdlib.h>
    int main() {
        printf("%d %d", abs(-7), (int)strtol("1010", NULL, 2));
    }

  58. Question 58 of 60 basics of pointers: pointer declaration, initialization, accessing values using pointers Hard

    Given char *s = "ABCD";, what does *(s + 2) - *s evaluate to?

  59. Question 59 of 60 function definition Hard

    What is the effect of defining int f(void) versus int f() in C?

  60. Question 60 of 60 recursion Hard

    What does g(1234) print?

    C
    void g(int n) {
        if (n == 0) return;
        g(n / 10);
        printf("%d", n % 10);
    }

That's unit 4

Answer a few questions and your score shows up here.