Question 61
Consider the following declaration :
struct addr {
char city[10];
char street[30];
int pin;
};struct {
char name [30];
int gender;
struct addr locate;
} person, *kd = &person;Then *(kd -> name + 2) can be used instead of
Step-by-Step Solution
Detailed Breakdown
Pointer Dereferencing (-> vs .):
The variable kd is a pointer to the structure variable person (*kd = &person;).
The arrow operator (->) is syntactically a shorthand for dereferencing a pointer and then accessing a member:
\(kd\rightarrow \text{
ame}\equiv (*kd).\text{
ame}\)Substituting into the Expression:
Substituting this equivalence directly into the target expression:
\(\text{*(}\mathbfit{kd\rightarrow }\text{
ame}+2\text{)}\implies \text{*(}\mathbfit{(*kd).}\text{
ame}+2\text{)}\)
This matches option (c) exactly.Why other options are incorrect:
• (a) person.name + 2: The array name person.name decays to a pointer (char *). Adding 2 to it results in a memory address (char *). However, the target expression has a dereferencing asterisk * at the very front, which retrieves the actual value (char) at that index.
• (b) kd -> (name + 2): This is syntactically invalid in C because name is not a standalone variable outside the structure scope, so it cannot be grouped with + 2 inside parentheses like that.