• Susaga@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      77
      ·
      3 months ago

      I think int*** is meant to be pointing at int**, but the image is just unclear about where everything is in perspective.

      • dohpaz42@lemmy.world
        link
        fedilink
        English
        arrow-up
        32
        arrow-down
        4
        ·
        3 months ago

        Pretty sure the image is clear:

        int*** -> int*
        int** -> int
        Int* -> int
        

        Clarity doesn’t mean correct. But that’s probably why it’s posted here. 🤷‍♂️

        • mexicancartel@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          9
          ·
          3 months ago

          int** is inside a TV, and persumably int* must be inside another TV(even though uts not edited in). The image perespective is showing one thing inside the other, inside the other. So when when int*** points the TV it reference int**, which reference int* which reference int. Its just edited very bad

        • Susaga@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          8
          ·
          3 months ago

          RT*** isn’t pointing at RT*, he’s pointing at the TV showing RT**. The fact you think otherwise is what makes the image unclear. I’m not sure why you insist on them being wrong.

          • _tasten_tiger@feddit.org
            link
            fedilink
            arrow-up
            1
            arrow-down
            1
            ·
            3 months ago

            But that doesn’t hold up, because RT** isn’t pointing at a TV containing RT* only RT*** is pointing at an TV containing RT** RT* and RT

    • ジン@quokk.au
      link
      fedilink
      English
      arrow-up
      3
      ·
      3 months ago

      That’s not the end of the chain either, right?

      Because : int -> &int -> &&int

      Or can you not use the address operator like that? It also might be int& &, I failed cs2200 on this exact type of technicality

  • 14th_cylon@lemmy.zip
    link
    fedilink
    arrow-up
    8
    ·
    3 months ago

    Why should the left one in the rectangle be int**? It doesn’t make sense to me, they are both clearly just int*

    What am i missing?

      • Technus@lemmy.zip
        link
        fedilink
        arrow-up
        12
        ·
        3 months ago

        Ah right, so that would be a 3D array.

        • T* is a single row of T
        • T** is a list of rows
        • T*** is a list of “layers” in the third dimension

        This would be incredibly hazardous to pass around as a bare pointer with no context, though. I’d expect to see this in a struct that, at minimum, also includes fields for the size of each dimension.

        • palordrolap@fedia.io
          link
          fedilink
          arrow-up
          3
          ·
          3 months ago

          In the C programming language. Or do you mean which C project specifically? Because as Technus surmises in their response, it’s usually a better idea to set up aliases (typedefs or heck, even #defines) so that you’re offloading some of the mental strain keeping track of the layers, and that’s likely to be what happens in production code.

          But the underlying data type is still T***.

    • ZILtoid1991@lemmy.worldOP
      link
      fedilink
      arrow-up
      7
      arrow-down
      1
      ·
      3 months ago

      The & operator references the value.

      int i;
      int* p = &i;
      

      In C++, the & at the function argument makes it a reference type (safe pointer).

      void someFunction(int& refVal) {
          [...]
      }
      
      • Flames5123@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        3
        arrow-down
        2
        ·
        3 months ago

        As someone who likes working with higher level languages, I never understood the pass by reference or even referencing different pointers. It never stuck out to me as useful in what I want software to do. It’s too close to hardware.

        • Sylvartas@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          10
          ·
          edit-2
          3 months ago

          Most of the time you pass by reference for more outputs, or by const ref to avoid copying a big-ass data structure (which is not always straightforward, with structures smaller than a pointer, which are pretty big in 64 bits architecture, you lose more to the ref overhead than to the copy IIRC)

          • DahGangalang@infosec.pub
            link
            fedilink
            arrow-up
            4
            ·
            3 months ago

            Another reason I commonly see: to change the structure / “main pointer” to a data structure (esp during freeing and cleanup).

        • ZILtoid1991@lemmy.worldOP
          link
          fedilink
          arrow-up
          1
          ·
          3 months ago

          Reference values are quite useful, such as:

          double valOut;
          if (parseDouble(valOut) == 0) { //Argument of parseDouble is ref type, no & needed for input, no exceptions needed for error handling
              [...] //No error, code executed normally
          } else {
              [...] //Erroreus input
          }
          
    • Dejected Warp Core@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      3 months ago

      *x = dereference or “point to”. Treats the variable x as containing a pointer value. Evaluates to a variable existing at the address in x.

      &x = reference or “get address of”. Evaluates to the address of x.

      They’re complimentary operators, so *(&x) cancels out and is equvalent to just x.

  • Deconceptualist@leminal.space
    link
    fedilink
    arrow-up
    3
    ·
    3 months ago

    The placement of the labels is a bit sloppy but I think it tracks. The character in the middle (int*) is pointing at int, then the one on the left (int**) is pointing at the middle one (int*), etc

    What I want to know: what is that shirt and where do I get it?

    • zerofk@lemmy.zip
      link
      fedilink
      arrow-up
      3
      ·
      3 months ago

      It’s what makes mages turn those squiggly lines on paper into fireballs.

      Not clerics though, they’re different.