Array and Pointer · Programming in C
54 questions · asked in 22 of 27 years (2000–2026)
MCQ 39 · MSQ 1 · NAT 141-mark 34 · 2-mark 20
2000Questions per year2026
Questions 11–15 of 54
Consider the following ANSI C program.
#include <stdio.h>
int main( )
{
int arr[4][5];
int i, j;
for (i=0; i < 4; i++)
{
for (j=0; j < 5; j++)
{
arr[i][j] = 10 * i + j;
}
}
printf("%d", *(arr[1]+9));
return 0;
} What is the output of the above program?Answer: (C)
arr[1] gives the address of arr[1][0]. Adding 9 moves the pointer 9 ints forward in row-major order. The position is 5 + 9 = 14, which is row 2, column 4.
So arr[2][4] = 10 2 + 4 = 24
Answer: 24
So arr[2][4] = 10 2 + 4 = 24
Answer: 24
Consider the following C program.
#include <stdio.h>
int main () {
int a[4] [5] = {{1, 2, 3, 4, 5},
{6, 7,8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17,18, 19, 20}};
printf("%d\n", *(*(a+**a+2)+3));
return(0);
}The output of the program is _______.Answer: 19
Here **a is the same as a[0][0], which is 1. So the expression becomes .
Row 3 is {16, 17, 18, 19, 20} a[3][3] is 19.
Answer: 19
Row 3 is {16, 17, 18, 19, 20} a[3][3] is 19.
Answer: 19
Consider the following C program:
#include <stdio.h>
int main(){
int arr[] = {1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip = arr + 4;
printf("%d\n", ip[1]);
return 0;
} The number that will be displayed on execution of the program is _________ .Answer: 6
Here ip = arr + 4 is the address of arr[4]. So ip[1] = *(ip + 1) = arr[5] = 6.
Answer: 6
Answer: 6
Consider the following C program:
#include <stdio.h>
int main() {
int a[] = {2, 4, 6, 8, 10};
int i, sum = 0, *b = a + 4;
for (i = 0; i < 5; i++ )
sum = sum + (*b - i) - *(b - i);
printf("%d\n", sum);
return 0;
} The output of above C program is __________ . Note: This was Numerical Type question.Answer: 10
Here b points to a[4], which is 10. Each loop pass adds this term:
- Step i = 0: 10 10 = 0
- Step i = 1: 9 8 = 1
- Step i = 2: 8 6 = 2
- Step i = 3: 7 4 = 3
- Step i = 4: 6 2 = 4
Adding all the terms, sum = 0 + 1 + 2 + 3 + 4 = 10
Answer: 10
- Step i = 0: 10 10 = 0
- Step i = 1: 9 8 = 1
- Step i = 2: 8 6 = 2
- Step i = 3: 7 4 = 3
- Step i = 4: 6 2 = 4
Adding all the terms, sum = 0 + 1 + 2 + 3 + 4 = 10
Answer: 10
Consider the following C program.
#include <stdio.h>
struct Ournode{
char x,y,z;
};
int main(){
struct Ournode p = {'1', '0','a'+2};
struct Ournode *q = &p;
printf("%c,%c",*((char*)q+1),*((char*)q+2));
return 0;
} The output of this program is:Answer: (A)
The struct stores the characters '1', '0' and 'a' + 2 = 'c' one after another in memory. (char*)q + 1 points to the 2nd byte, which is '0'. (char*)q + 2 points to the 3rd byte, which is 'c'. The %c format prints a character with no quotes.
Answer: 0, c
Answer: 0, c
Keep practising