Arrays
- Which of the following statements are correct about 4 used in the following C expressions?
int num[4] ;
num[4] = 23 ;
-
View Hint View Answer Discuss in Forum
In the first statement 4 specifies the array size.
Correct Option: B
In the first statement 4 specifies the array size, whereas in the second statement it specifies a particular element of the array.
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int Array[2][5];
Array[][] = {{10, 20, 30, 40, 50}, {40, 50, 60, 70, 80}};
printf("%d\n", Array[3][4]);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Compilation Error
main.c: In function ‘main’:
main.c:5:15: error: expected expression before ‘]’ token
Array[][] = {{10, 20, 30, 40, 50}, {40, 50, 60, 70, 80}};
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int num[3][4][5], k = 12;
num[0][0] = &k;
printf("%d\n", *num[0][0]);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Compilation Error
main.c: In function ‘main’:
main.c:5:19: error: assignment to expression with array type
num[0][0] = &k;
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
N(num);
}
void N(int **num)
{
int n1 = 15, n2 = 15, n3 = 12;
int *num[2];
num[0] = &n1;
num[1] = &n2;
printf("%d\n", num[0][1]);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Compilation Error
main.c: In function ‘main’:
main.c:4:9: warning: implicit declaration of function ‘N’ [-Wimplicit-function-declaration]
N(num);
^
main.c:4:11: error: ‘num’ undeclared (first use in this function)
N(num);
^~~
main.c:4:11: note: each undeclared identifier is reported only once for each function it appears in
main.c: At top level:
main.c:6:10: warning: conflicting types for ‘N’
void N(int **num)
^
main.c:4:9: note: previous implicit declaration of ‘N’ was here
N(num);
^
main.c: In function ‘N’:
main.c:9:14: error: ‘num’ redeclared as different kind of symbol
int *num[2];
^~~
main.c:6:18: note: previous definition of ‘num’ was here
void N(int **num)
- 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]);
}
-
View Hint View Answer Discuss in Forum
NA
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;