CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following C program:
#include <stdio.h>
struct ournode {
char x, y, z;
};
int main ( ) {
struct our node p = { '1', '0', 'a' + 2};
struct ournode *a = &p;
printf("%c,%c ", *((char*)q + 1),
*((char*) q+ 2));
return 0;
}
The output of this program is:

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

The correct option is A 0, c

Since we know ‘a’ + 2 = skip ‘a’, ‘b’, i.e. 'c'
Now *q = &
i.e. now q point to struct p.
So, *((char*) q + 1)) will typecast structure into char and skip one char and points to ‘0 i.e.
addresses ‘101’ and *(101) = 0.
And *((char*) q + 2) will typecast structure into char and skip two char and points to ‘c’ i.e. addresses ‘102’ and *(102) = c.
Final output by given code is 0,c.

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