• pewpew@feddit.it
    link
    fedilink
    arrow-up
    13
    ·
    8 months ago

    Whats the difference between void fn(Type& var) and void fn(Type* var)?

    • Tangent5280@lemmy.world
      link
      fedilink
      arrow-up
      33
      arrow-down
      4
      ·
      8 months ago

      Sends original data vs making a copy of data and sending it.

      In meme context you’d be just making a copy of your consciousness and putting it in a machine. Whatever reason you’re doing it for - escape illness, survive armageddon, nothing changes for you. A copy of you lives on though.

    • cbazero@programming.dev
      link
      fedilink
      arrow-up
      9
      arrow-down
      1
      ·
      8 months ago

      I guess you ask for C++. There Type* can be null while Type& can’t be null. When it gets compiled Type& is compiled (mostly) to the same machinecode as Type*.

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      7
      ·
      8 months ago

      You can pass nullptr in the second example (that is not what OP wrote though, hes second is making a copy).