Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Arrays Questions
Predict the output in Turbo C (16-bit DOS environment): #include
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; }
Double indirection and 2D array decay: What value prints? #include
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); }
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
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; }
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
int main() { int arr[] = {2, 3, 4, 1, 6}; printf("%u, %u, %u ", arr, &arr[0], &arr); return 0; }
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
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; }
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
int main() { int arr[1] = {10}; printf("%d ", 0[arr]); return 0; }
1
2