GATE | Gate IT 2008 | Question 50

C program is given below:

filter_none

edit
close

play_arrow

link
brightness_4
code

# include <stdio.h>
int main ()
{
        int i, j;
        char a [2] [3] = {{'a', 'b', 'c'}, {'d', 'e', 'f'}};
        char b [3] [2];
        char *p = *b;
        for (i = 0; i < 2; i++) {
              for (j = 0; j < 3; j++) {
              *(p + 2*j + i) = a [i] [j];
              }
        }
}
 /* Add code here. Remove these lines if not writing code */ 

chevron_right


What should be the contents of the array b at the end of the program?
(A) a b
c d
e f
(B) a d
b e
c f
(C) a c
e b
d f
(D) a e
d c
b f


Answer: (B)

Explanation: *p= a[0][0]
*(p+2) = a[0][1]
*(p+4) = a[0][2]
*(p+1) = a[1][0]
*(p+3) = a[1][1]
*(p+5) = a[1][2]


Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.