wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

A C-program is given below:

# 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];
}
}
}

What should be the contents of the array b at the end of the program?

A
a b
c d
e f
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
a c
e b
d f
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
a d
b e
c f
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
a e
d c
b f
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C a d
b e
c f
char [2] [3] = {{'a', 'b', 'c',} {'d', 'e', 'f'}}


char *p = *b make new char pointer p which pointed to array b.


*(p + *j + i) = a[i] [j]; will assign element of array a to array b, by scanning array 'd' row wise and sorting character in array 'b' column wise.

Final array b[3] [2] will be:


flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon