• Technus@lemmy.zip
        link
        fedilink
        arrow-up
        12
        ·
        18 days 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
          ·
          18 days 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***.

  • 14th_cylon@lemmy.zip
    link
    fedilink
    arrow-up
    6
    ·
    18 days 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?

    • ZILtoid1991@lemmy.worldOP
      link
      fedilink
      arrow-up
      2
      arrow-down
      2
      ·
      18 days ago

      No, you need to learn a lot more. Other programming concepts, programming paradigms, algorithms, and many more.

    • ZILtoid1991@lemmy.worldOP
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      18 days 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
        ·
        18 days 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.

        • lime!@feddit.nu
          link
          fedilink
          arrow-up
          9
          ·
          18 days ago

          if you’re working with higher level languages you pass-by-reference all the time. give a list to a function to modify it? that’s by reference. giving an event handler function to a framework? that’s by reference. setting a property on an object? that’s usually by reference.

          • funkless_eck@sh.itjust.works
            link
            fedilink
            arrow-up
            1
            arrow-down
            1
            ·
            18 days ago

            the list is the helpful part to understanding it.

            it would be terrible if, with bar being a list and foo being a member of the list

             if foo in bar: return true
            

            modified the list. So yeah, you want to look at the list not edit the list, it’s a pointer.

            • lime!@feddit.nu
              link
              fedilink
              arrow-up
              3
              ·
              18 days ago

              other way round surely? if you want to modify the original object, use a pointer. if you don’t, use a copy.

            • gerryflap@feddit.nl
              link
              fedilink
              arrow-up
              1
              ·
              18 days ago

              Your example doesn’t make sense to me. Why would you modify the entire list by checking if something is in it? Also, you can totally edit the list via a pointer, that’s how you’re supposed to edit the list if you want any performance. Otherwise you’d be copying the list on every modification, which is terribly inefficient

        • ZILtoid1991@lemmy.worldOP
          link
          fedilink
          arrow-up
          1
          ·
          18 days 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
      3
      ·
      18 days 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.

    • zerofk@lemmy.zip
      link
      fedilink
      arrow-up
      2
      ·
      17 days ago

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

      Not clerics though, they’re different.

  • Deconceptualist@leminal.space
    link
    fedilink
    arrow-up
    2
    ·
    18 days 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?