retagged by
5,659 views
5 votes
5 votes

Consider the following declaration :

structaddr {
    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. $person.name+2$
  2. $kd-> (name+2)$
  3. $*((*kd).name+2)$
  4. either $A)$ or $B)$ , not $C)$
retagged by

3 Answers

Best answer
10 votes
10 votes
Option C is correct. A and B points to the address of the location whereas we require to access the value at that location, which is the third character of name.
edited by
3 votes
3 votes

-> belongs to postfix production which has higher precedence than +. So, *(kd->name+2) is equivalent to *((*kd).name+2) which is (*kd).name[2]. Ans = (C)

0 votes
0 votes

None of the given options is correct. If we observe carefully the first line is like structaddr {. There is no space between struct and addr. So it will give following error:

main.c: In function 'main':
main.c:12:5: error: 'structaddr' undeclared (first use in this function)
     structaddr {
     ^

Had there been space between struct and addr, one of the given options would have been correct. But since in question paper, there is no space between struct and addr in first line. So the given code will give error and hence none of the options is matching (or you can say all options are matching because with all options, same error will be there). So in ISRO marks should be given to all or this question should be removed from final evaluation.

Answer:

Related questions

5 votes
5 votes
2 answers
1
Arjun asked Apr 22, 2018
8,590 views
Consider the following program{ int x=1; printf("%d",(*char(char*)&x)); }Assuming required header files are included and if the machine in which this program is executed ...
1 votes
1 votes
2 answers
2