Consider the following declaration : Cstruct addr { char city[10]; char…

2018

Consider the following declaration :

C
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

  1. A.

    person.name +2

  2. B.

    kd -> (name +2 )

  3. C.

    *((*kd).name + 2 )

  4. D.

    either (A) or (B), but not (C)

Attempted by 251 students.

Show answer & explanation

Correct answer: C

The arrow operator (->) accesses struct members via a pointer. kd->name is equivalent to (*kd).name. The expression *(kd -> name + 2) retrieves the character at index 2 of the name array. This is equivalent to (*kd).name[2].

Explore the full course: Isro