Arrays Questions

Practice Arrays MCQs with answers and explanations. Page 2 of 2.

Category
C# Programming
Topic
Arrays
Page
2 / 2
Mode
Practice

Questions

Open any question to view the answer and explanation.

Predict the output in Turbo C (16-bit DOS environment): #include<stdio.h> int main() { int arr[5], i = 0; while(i < 5) arr[i] = ++i; for(i = 0; i < 5; i++) printf("%d, ", arr[i]); return 0; }
Open
View answer
Double indirection and 2D array decay: What value prints? #include<stdio.h> void fun(int **p); int main() { int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; int *ptr; ptr = &a[0][0]; fun(&ptr); return 0; } void fun(int **p) { printf("%d ", *p); }
Open
View answer
In C language on a 16-bit system where each int occupies 2 bytes, consider the following 2D array a with 3 rows and 4 columns. If the base address of the array a begins at 65472 in memory, what numeric addresses will be printed for (a + 1) and (&a + 1) using %u (treating them as unsigned addresses)? #include<stdio.h> int main() { int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; printf("%u, %u ", a+1, &a+1); return 0; }
Open
View answer
In C, when printing the addresses of an array and its first element on a typical system conceptually viewed with 2-byte ints, suppose the array arr begins at address 1200. What values are printed for arr, &arr[0], and &arr using %u? #include<stdio.h> int main() { int arr[] = {2, 3, 4, 1, 6}; printf("%u, %u, %u ", arr, &arr[0], &arr); return 0; }
Open
View answer
In C, evaluate the effects of pre-increment and post-increment on array elements and indices. For the array and statements below, what values are printed for i, j, and m? #include<stdio.h> int main() { int a[5] = {5, 1, 15, 20, 25}; int i, j, m; i = ++a[1]; j = a[1]++; m = a[i++]; printf("%d, %d, %d", i, j, m); return 0; }
Open
View answer
In C, array subscripting x[y] is defined as *(x + y). Using this property, what does the expression 0[arr] print for an array declared as int arr[1] = {10}? #include<stdio.h> int main() { int arr[1] = {10}; printf("%d ", 0[arr]); return 0; }
Open
View answer

Practice smarter

Solve a few questions daily and revisit weak topics regularly to improve accuracy.