Home » C Programming » Arrays » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    int num[4][5];
    f(num);
    }
    void f(int (*num)[4])
    {
    int n1 = 15, n2 = 13, n;
    num[0] = &n1;
    num[1] = &n2;
    for (n = 0; n < 2; n++)
    printf("%d\n", *num[n]);
    }
    1. Compilation Error
    2. Garbage value
    3. Undefined behaviour
    4. Compilation Error
    5. segmentation fault/code crash
Correct Option: D

Compilation Error

main.c: In function ‘main’:
main.c:5:9: warning: implicit declaration of function ‘f’ [-Wimplicit-function-declaration]
f(num);
^
main.c: At top level:
main.c:7:10: warning: conflicting types for ‘f’
void f(int (*num)[4])
^
main.c:5:9: note: previous implicit declaration of ‘f’ was here
f(num);
^
main.c: In function ‘f’:
main.c:10:16: error: assignment to expression with array type
num[0] = &n1;
^
main.c:11:16: error: assignment to expression with array type
num[1] = &n2;



Your comments will be displayed only after manual approval.