2 votes 2 votes int main() { int *r2; void abc(int **); abc(&r2); printf("%d",*r2); } void abc(int **r3) { int r1=5; /* add statements here */ } Which statement is added to the above program such that the address of r1 gets stored in r2? A) *r2 = &r1; B)*r1 = &r3; C) *r3 = &r1; D) None of these Programming in C programming-in-c pointers + – Sankaranarayanan P.N asked Sep 28, 2016 Sankaranarayanan P.N 818 views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply srestha commented Sep 28, 2016 reply Follow Share Answer C) here but void abc(int **); this line inside main() is not needed 1 votes 1 votes vijaycs commented Sep 28, 2016 reply Follow Share but , r1 is local variable to function abc. So after completion of function abc, *r3 will behave like dangling pointer. correct me if i am wrong. 1 votes 1 votes srestha commented Sep 28, 2016 reply Follow Share yes, even r2 will work like a dangling pointer.rt? 1 votes 1 votes vijaycs commented Sep 28, 2016 reply Follow Share yes. 0 votes 0 votes Please log in or register to add a comment.
Best answer 5 votes 5 votes int main() { int *r2; void abc(int **); abc(&r2); printf("%d",*r2); } void abc(int **r3) { Static int r1=5; *r3 = &r1; } Program should be like this, if address of r1 gets stored in r2 . Kapil answered Sep 28, 2016 selected Sep 28, 2016 by vijaycs Kapil comment Share Follow See all 3 Comments See all 3 3 Comments reply vijaycs commented Sep 28, 2016 reply Follow Share And if it is int r1 =5; then for this particular question , we can go with ans D right ? 0 votes 0 votes Kapil commented Sep 28, 2016 reply Follow Share Then, if option undefined behaviour is here, i will go with that, as it is UB (segmentation fault) But, nothing is here like that , Then, option D is best . 0 votes 0 votes Cinu Skaria commented Sep 30, 2016 reply Follow Share On executing the program with *r3=&r1, the output obtained is 5. 0 votes 0 votes Please log in or register to add a comment.