1. How large is the Person struct on a 32-bit machine? a)36 bytes b)38 bytes c)4
ID: 670241 • Letter: 1
Question
1. How large is the Person struct on a 32-bit machine?
a)36 bytes
b)38 bytes
c)40 bytes
d)42 bytes
2. Which of the following is equal to y->id?
a)&y->id
b)&x.id
c)x.id
d)*x->id
3. Which of the following is a valid replacement for line 7?
a)scanf(“%c”, &x->gender);
b)scanf(“%c”, &((*y).gender));
c)scanf(“%c”, x.gender);
d)scanf(“%s”, &y->gender);
4. If we input “Greg” for the name. What is the value of
*(y->name)?
a)The address of the array containing “Greg”
b)‘G’
c)The address of y
d)Undefined
5. What is the type of (&*y->name)?
a)char
b)struct Person*
c)char**
d)char*
Could u help me to solve these questions?
#include stdio.h #pragma warning(disable : 4996) Accessing Members of a Struct struct Person int id; char name [30]; char gender; // need padding? int main() f 1 2 4 5 6 7 8 9 y = &x; scanf("%d", &(y->id)); printf("%din.. , x.id); scant( "%s'. , (*y).name); printf("%s ", (8x)-name); fflush (stdin); x,gender = get char(); printt ntfCXc ", y-gender): return 0;Explanation / Answer
1.
The correct option for 1 bit is (a)
Explanation:
Ths size of the Structure Person is 36 bytes.
The Person structure contains
a character (1byte), a character array (30bytes)
and integer (4bytes ) in 32-bit machine.
Since C-structure uses padding alignment
to properly get the addresses.
1 byte is added immediately after character
byte
char(1byte)+padding(1byte)+char array(30bytes)+
integer(4bytes)=36=8*4bytes.
32-bit systems process in word size of lenght of 4 bytes.
--------------------------------------------------------------------------------------------------
2.
The correct option is (d)
The d option *x->id is equal to y->id.
since y=&x, the y takes address of the
structure x.
The pointer x is pointer to a variable.
So the *x->id is the correct option.
-------------------------------------------------------------------------------------------
3.
The correct option is (b)
The variable y is takes the address of x variable.
To read a character at the gender , we need
address to store &.
So the correct answer is
scanf("%c",&((*y).gender));
-------------------------------------------------------------------------------------------
4.
The correct option is (c) The address of y
The *(y->name) prints the address of the name in the structure pointer
variable y.
---------------------------------------------------------------------------------------------
5.
The correct option is (c) The address of d
In c, a character array is treated as pointer , since
the name variable points to the starting address of the variable.
To read pointer to pointer then char ** type is used.
Hope this helps you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.