Subscripted arrays in C -
is possible create subscripted array in c uses array indexes. went through link: idl — using arrays subscripts
arrays can used subscripts other arrays. each element in subscript array selects element in subscripted array.
for example, consider statements:
a = [6, 5, 1, 8, 4, 3] b = [0, 2, 4, 1] c = a[b] print, c this produces following output:
6 1 4 5 is above possible in c programming.
arrays can used subscripts other arrays. each element in subscript array selects element in subscripted array.
syntactically not directly possible in c. you've use loop achieve this.
int a[] = {6, 5, 1, 8, 4, 3}; int b[] = {0, 2, 4, 1}; (int = 0; < (sizeof(b)/sizeof(b[0])); ++i) printf("%d\n", a[b[i]]); if want neat, wrap in function , should alright:
// returns no. of elements printed // returns -1 when index out of bounds int print_array(int *a, int *b, size_t na, size_t nb) { int = 0; (i = 0; < nb; ++i) { int const index = b[i]; if (index >= na) return -1; print("%d\n", a[index]); } return i; }
Comments
Post a Comment