Why can I assign a new value to a reference, and how can I make a reference refer to something else?

    • a) It cannot, the line you quote doesn’t change the reference q, it changes p.
    • b) No the literal is constant, but p is a pointer which points at a literal.
      The pointer can be changed, what is being pointed to cannot.
      q = "world"; makes the pointer p point to something else.
  1. You seem to think that this code

    int i;
    int &j = i;
    int k;
    j = k;
    

    is reassigning a reference, but it isn’t.
    It’s assigning the value of k to i, j still refers to i.
    I would guess that this is your major misunderstanding.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)