Arrays


  1. What will be the output of the following C code?
     #include <stdio.h>
    void function(int number[][])
    {
    number[0][1] = 12;
    int k = 0, L = 0;
    for (k = 0; k < 2; k++)
    for (L = 0; L < 3; L++)
    printf("%d", number[k][L]);
    }
    void main()
    {
    int number[2][3] = {0};
    function(number);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Compilation Error

    main.c:2:23: error: array type has incomplete element type ‘int[]’
    void function(int number[][])
    ^~~~~~
    main.c:2:23: note: declaration of ‘number’ as multidimensional array must have bounds for all dimensions except the first
    main.c: In function ‘main’:
    main.c:13:18: error: type of formal parameter 1 is incomplete
    function(number);


  1. Comment on the following 2 arrays with respect to I and II.
       int *num1[10];
    int *(num2[10]);
    I. Array of pointers
    II. Pointer to an array











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    num1 is I, num2 is I



  1. Comment on the following C statement.
    int (*num)[12];











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    A pointer “num” to an array


  1. What will be the output of the following C code?
    #include 
    void f(int n[5][])
    {
    n[0][4] = 11;
    int k = 0, L = 0;
    for (k = 0; k < 4; k++)
    for (L = 0; L < 5; L++)
    printf("%d", n[k][L]);
    }
    void main()
    {
    int n[4][5] = {0};
    f(n);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    Compilation Error

    main.c:2:16: error: array type has incomplete element type ‘int[]’
    void f(int n[5][])
    ^
    main.c:2:16: note: declaration of ‘n’ as multidimensional array must have bounds for all dimensions except the first
    main.c: In function ‘main’:
    main.c:13:11: error: type of formal parameter 1 is incomplete
    f(n);



  1. What will be the output of the following C code?
    #include <stdio.h>
    void main()
    {
    int Array[2][3] = {11, 21, 31, , 41, 51};
    int k = 0, L = 0;
    for (k = 0; k < 2; k++)
    for (L = 0; L < 3; L++)
    printf("%d", Array[k][L]);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Compilation Error

    main.c: In function ‘main’:
    main.c:4:40: error: expected expression before ‘,’ token
    int Array[2][3] = {11, 21, 31, , 41, 51};