643 views
5 5 votes

Should this question be invalid? 

t[4] Mentions 4 elements, but question assigns 5 elements.
Because according to my knowledge accessing element t[4] (if we consider index to be from 0 to 4, also it's by default in C) should give out of bound error.
Answer for this question was 'Option C'.

3 Answers

1 1 vote
Answer will be Option D :  4 3 0 1 2

Explanation :

t[0]=2; t[1]=3; t[2]=4 ; t[3]=1 ; t[4]=0;

for i=0 : t[t[t[i]]] = t[i]  , here t[t[t[i]]] means t[4] which is  2, as t[0]=2;

for i=1 : t[t[t[i]]] = t[i]  , here t[t[t[i]]] means t[1] which is  3, as t[1]=3;

for i=2 : t[t[t[i]]] = t[i]  , here t[t[t[i]]] means t[0] which is  4, as t[2]=4;

for i=3 : t[t[t[i]]] = t[i]  , here t[t[t[i]]] means t[3] which is  1, as t[3]=1;

for i=4 : t[t[t[i]]] = t[i]  , here t[t[t[i]]] means t[2] which is  0, as t[4]=0;
0 0 votes
c option beacause their was only change when for loop run  first time for i= 0 t[ t [t [i] ] ] = t[i]

then t[4] = 2

and for i= 1,2,3,4 loop will run but no change occur in the array

so they printed 2,3,4,1,2
Position:
Show:

Related questions

2 2 votes
1 1 answer
810
810 views
shivamSK asked Jun 15, 2024
810 views
#include <stdio.h int main () { int i, k; int a [8] = {33,34,35,36,37,40,50,38}; for(i = 0; i < 3; i++) { a[i] = a[i] + 1; i=i+1; } i=i-1; for (k = 7; k 4; k ) { int i =...
0 0 votes
0 0 answers
548
548 views
Debargha Mitra Roy asked Aug 14, 2024
548 views
If $n$ has the value $3$, then the statement $a[++n]=n++$;(A) assigns $3$ to $a[5]$(B) assigns $4$ to $a[5]$(C) assigns $4$ to $a[4]$(D) assigns a compiler-dependent valu...
3 3 votes
2 2 answers
968
968 views
kirmada asked Jun 20, 2024
968 views
#include <stdio.h int main() { int (*a) ; int arr[4][4]={1,2,3,4,6,7,8,9}; a=arr; ++a; printf("%d", a); return 0; }what is the answer NUMARICAL ?