Sunday, September 15, 2013

C Debugging Interview question

Find output of following code:

c interview questionsint main(){
    register int a=5;
    int *rp=&a;
    int **rpp=&rp
    printf("%d\n",**rp);  
    getch(); 
}

Answer: Error
Explanation: We can’t request address of a register variable. It is illegal to apply & operator to a variable declared as a register.

2 comments:

  1. ur solution is wrong...

    chk this link:
    http://ideone.com/UYQmAp

    ReplyDelete
  2. @above
    You have coded it in c++. The question was with respect to c language.
    see
    http://stackoverflow.com/questions/1256246/address-of-register-variable for detailed explanation

    ReplyDelete