Given int arr[3][4][2]= {{{2,4},{7,8},{3,4},{5,6}},{{7,6},{3,4},{5,3},{2,3}},{{8.9},{7,2},{3,4},{5,1}}}; Which one of the following can be used to refer to element 1 in the above 3-d array?
*(*(*(arr+2)+3)+1)
In C, arr[i][j][k] is defined as *(*(*(arr+i)+j)+k): each subscript is pointer arithmetic on the array name followed by a dereference. Valid indices for int arr[3][4][2] are i = 0–2, j = 0–3, k = 0–1.
Step 1 — The initializer lists three 4×2 blocks. The third block (i = 2) is {{8.9},{7,2},{3,4},{5,1}}; its fourth row (j = 3) is {5,1}, and 1 is its second element (k = 1). So element 1 is arr[2][3][1].
Step 2 — Rewriting with pointers: arr+2 points to block 2, *(arr+2)+3 points to its row 3, *(*(arr+2)+3)+1 points to the element at k = 1, and the outer * reads it: *(*(*(arr+2)+3)+1) = arr[2][3][1] = 1.
Step 3 — arr[3][4][2] uses the declared sizes as indices and lies outside the array; arr[2][3][2] uses k = 2, past the last valid index 1 of the innermost dimension; *(arr+2)+*(arr+3)+*(arr+1) tries to add pointers to sub-arrays (and arr+3 is past the end), which is not an element access at all.
*(*(*(arr+2)+3)+1) option is correct.
A three dimensional array in ‘C’ is declared as int A[x][y][z]. Here, the address of an item at the location A[p][q][r] can be computed as follows (where w is the word length of an integer) :
When we pass an array as an argument to a function, what actually gets passed ?
Which of the following is true for computation time in insertion, deletion and finding maximum and minimum element in a sorted array ?
Consider an array A[20, 10], assume 4 words per memory cell and the base address of array A is 100. What is the address of A[11, 5] ? Assume row major storage.
When an array is passed as parameter to a function, which of the following statements is correct ?
Consider the following C program segment.
#include <stdio.h>
int main()
{
char s1[7] = "1234";
char *p;
p = s1 + 2;
*p = '0';
printf("%s", s1);
return 0;
}
#include <stdio.h>
void foo(int *p, int x){
*p = x;
}
int main(){
int *z;
int a = 20, b = 25;
z = &a;
foo(z, b);
printf("%d", a);
return 0;
}
What is the output the given C language code snippet?
#include<stdio.h>
int main()
{
int x[] = {10,20,30};
int *p = x;
p++;
printf("%d",*p);
return 0;
}
Which of the following expression will delete the entire array pointed to by q?