Thread 105711325 - /g/ [Archived: 832 hours ago]

Anonymous
6/26/2025, 4:48:22 PM No.105711325
dp
dp
md5: b8126e00dbb7c62bfd8214589c3c6e88๐Ÿ”
WHY ARE THERE POINTERS TO POINTERS
Replies: >>105711346 >>105711348 >>105711364 >>105711394 >>105711466 >>105711627 >>105711842 >>105712278 >>105713350 >>105713380 >>105713616 >>105713648 >>105714817 >>105714827 >>105714829 >>105715582
Anonymous
6/26/2025, 4:50:19 PM No.105711346
>>105711325 (OP)
And?
Anonymous
6/26/2025, 4:50:30 PM No.105711348
>>105711325 (OP)
what if you have to point to a pointer
Anonymous
6/26/2025, 4:52:08 PM No.105711364
r01sq96mnz691
r01sq96mnz691
md5: 67d58c32043eb8e2f524b1d74e516e1b๐Ÿ”
>>105711325 (OP)
Replies: >>105711417
Anonymous
6/26/2025, 4:55:30 PM No.105711394
>>105711325 (OP)
To modify or return pointers aka objects. Also multidimensional arrays, linked lists, trees, et al
Anonymous
6/26/2025, 4:57:58 PM No.105711417
>>105711364
More trannime explanations of code please
Anonymous
6/26/2025, 4:59:42 PM No.105711426
write access to the write access
Anonymous
6/26/2025, 5:03:49 PM No.105711466
>>105711325 (OP)
For 2D arrays for example
You have an array of ints pointed by int*
something like [1,2,3] and then array of int* pointed to by int**

int**=> [int*=>[1,2,3],
int*=>[4,5,6],
int*=>[7,8,9]]
Replies: >>105711589 >>105713490 >>105715147
Anonymous
6/26/2025, 5:15:34 PM No.105711589
>>105711466
why not just int a[3][3]?
Replies: >>105711692 >>105715204
Anonymous
6/26/2025, 5:20:26 PM No.105711627
1673910399611140
1673910399611140
md5: 0ea5df50296297eb23590b2f5500bd85๐Ÿ”
>>105711325 (OP)
Data is data, anon. Memory address is just a number, you can point to any memory regardless of what it holds. You can make a pointer point at itself if you wanna.
Anonymous
6/26/2025, 5:24:32 PM No.105711666
1728975343113090
1728975343113090
md5: a8ac65f146b65a2d697a7d4b94080013๐Ÿ”
Your computer has little boxes inside it.
All the boxes have funny names like 0xea37168f43ec58bf. But that's a hard to remember computer name. That's called the address. It's like a mail address for the little boxes in your computer!
When you make a program, you write easy to remember names on the boxes. That's called declaring a variable. When you label the box like that, you can put things in the box and get them out easily because you remember you put them in the box labeled whatever.
You can put all sorts of things in the boxes, like numbers and letters. You can even put in the address of other boxes. A box that contains the address of another box is called a pointer.
You might not remember the address of the boxes you wrote labels on (variables), but you can ask the computer to tell you it. If you've got a box called a, you can ask for the address with &a. Then you can put that address inside one of your pointer boxes.
Maybe you've got an address written in one of your pointer boxes, but you want to find out what's in the box written on the label. If you have a pointer box called p, you can ask the computer to get you what's inside the box that's being pointed to with *p. That's called dereferencing a pointer.
Pointers can point to any kind of box, even other pointer boxes. You can even put in a fake address of a box that doesn't exist, or no address at all (null pointer). But you better be careful if you try to dereference one of those, because the computer will get angry and crash.
Most boxes only contain one value, but with pointers, you can do some fun things like point to the start of an array of boxes. That means you could store lots of data in boxes that are right next to each other so they're easy to access together. You only need to remember the address of the first box, which is what a pointer can help you with.
You could even point to an array of pointers, each pointing to their own array of boxes.
Replies: >>105711718
Anonymous
6/26/2025, 5:26:49 PM No.105711692
>>105711589
Ok modify [3][3] in a function. Oops I need a pointer. Okay, now do pointer things to that pointer. Oops, I need it to be a pointer to a pointer.

capiche?
Replies: >>105711763
Anonymous
6/26/2025, 5:29:39 PM No.105711718
>>105711666
ah yes. when moving i always have a box for telling me whats in another box... can't forget my box for telling me what's in that box too! im so forgetful
Replies: >>105711738 >>105711823
Anonymous
6/26/2025, 5:31:40 PM No.105711738
1727841538363418
1727841538363418
md5: 3a9a6e0fcd9babd4ddc146b16ee422c8๐Ÿ”
>>105711718
No! It doesn't tell you what's in the box! It tells you WHERE the box is!
Replies: >>105711801
Anonymous
6/26/2025, 5:34:49 PM No.105711763
>>105711692
ohhhhhhh
Anonymous
6/26/2025, 5:38:48 PM No.105711801
mb
mb
md5: 27436b53af59025ccea664219fbd6440๐Ÿ”
>>105711738
sorry anya
Anonymous
6/26/2025, 5:41:34 PM No.105711823
>>105711718
think of it as a shop catalog
brick is the data, let's say it's a purple brick
catalog saying "pick up your brick on this shelf" is pointer to data, it doesn't know that the brick is purple but it knows that it's brick-type
a line in catalog's table of contents saying "bricks, page 5" is a pointer to pointer to pointer, it points to page 5 that points to shelf where our purple brick resides
someone can change the brick to yellow, but you'll still have the same catalog so you'll find your brick
new edition of the catalog can change the shelf it tells you to pick up bricks from, but table of contents can stay the same since it's all still on page 5
Replies: >>105711854
Anonymous
6/26/2025, 5:43:50 PM No.105711842
>>105711325 (OP)
Imagine you have something the dynamically allocates memory, you're not sure where it is going to be allocated but you need to access it. If you're the code that creates it youll get the pointer back. Now imagine multiple areas need to access that memory. You could pass the pointer around, or you could store the pointer in a known location. Then you could use a pointer to that known location in those multiple areas so that they can easily find that allocated memory without having to allocate it themselves
Anonymous
6/26/2025, 5:44:55 PM No.105711853
Variables are just pointers with human understandable names.
Replies: >>105711907
Anonymous
6/26/2025, 5:45:00 PM No.105711854
>>105711823
Some chucklefuck moved the shelf so when I got there I Segmentation fault (core dumped)
Replies: >>105711868
Anonymous
6/26/2025, 5:46:06 PM No.105711868
1737805633515481
1737805633515481
md5: 7a2cf98a9ed794170d9fc9253bcbab54๐Ÿ”
>>105711854
Anonymous
6/26/2025, 5:47:40 PM No.105711887
Wait until OP learns about pointers to pointers to pointers.
Wait until he learns arrays are like pointers.
I wonder how OP will react when he learns hashmaps and realizes all languages with multidimensional datasets are juggling points.
Think about how many multidimensional pointers to structs and associated hashmaps need to be iterated through and processed just to render a web page every time something on the page changes.
And now you truly understand how bad tech has gotten.
Replies: >>105711913 >>105711925
Anonymous
6/26/2025, 5:50:20 PM No.105711904
If you have for example a function to get some element of an array, you may want to return it as a pointer because you donโ€™t know if the element exists.
Say you have a Find function, and you have a list of 3 elements and call Find(5), then that could crash your program. Instead Find returns a pointer to the found element. Now, if itโ€™s out of bounds, itโ€™s just a nullptr.
What happens if the list is not a list of values, but a list of pointers?
Anonymous
6/26/2025, 5:50:24 PM No.105711907
>>105711853
No not really
Replies: >>105713234
Anonymous
6/26/2025, 5:50:56 PM No.105711910
My first job, years back, I was working in a massive 20 million LOC C++ codebase, mostly from the 90s. I saw fucking triple pointers all the time. It was hell on Earth but put hair on my chest.
Replies: >>105715548
Anonymous
6/26/2025, 5:51:24 PM No.105711913
>>105711887
Who is confused by pointers??? Nigger itโ€™s like finding index fingers confusing
Replies: >>105711949
Anonymous
6/26/2025, 5:52:35 PM No.105711925
>>105711887
it's already happening anon...

is it too late to crawl back to js?
Anonymous
6/26/2025, 5:56:06 PM No.105711949
>>105711913
I didn't say they're confusing. I'm saying modern tech is a clusterfuck because people keep trying to abstract pointers away causing layers of overly complex spaghetti code that no one understands.
Anonymous
6/26/2025, 6:40:05 PM No.105712278
>>105711325 (OP)
>why are there arrays
Anonymous
6/26/2025, 8:13:30 PM No.105713234
>>105711907
>No not really
No kinda exactly.
Anonymous
6/26/2025, 8:22:57 PM No.105713350
>>105711325 (OP)
So we can have a listless link list
Anonymous
6/26/2025, 8:25:12 PM No.105713380
>>105711325 (OP)
Less analogy. More programming.
You will learn it intuitively. A lot of learning is done subconsciously.
Stop looking for the best explanation/article/video/book. And just do it.
Replies: >>105713681
Anonymous
6/26/2025, 8:37:22 PM No.105713490
>>105711466
>2D array
Flatten that shit into a 1D array for obvious performance reasons.
Replies: >>105713610 >>105715147
Anonymous
6/26/2025, 8:50:02 PM No.105713610
>>105713490
Source?
Replies: >>105713800
Anonymous
6/26/2025, 8:50:45 PM No.105713616
>>105711325 (OP)
because object which you have a pointer of might have an object inside
because an array cells might store pointers to other arrays
Anonymous
6/26/2025, 8:54:20 PM No.105713648
>>105711325 (OP)
Because Dennis Ritchie copied it from other people. He didn't invent anything.
Anonymous
6/26/2025, 8:57:03 PM No.105713681
>>105713380
I kinda dove headfirst into network/socket programming trying to do exactly this. A lot of the explanations here did help though especially about multidimensional arrays.
Anonymous
6/26/2025, 9:11:07 PM No.105713800
>>105713610
>why is a single contiguous area of memory more efficient than a contiguous area containing pointers to other contiguous areas scattered everywhere?
I bet you can't even tell why almost all list implementations are arrays instead of linked lists, loser.
Replies: >>105714928 >>105715133
Anonymous
6/26/2025, 10:47:50 PM No.105714817
>>105711325 (OP)
Wait until you come across the higher levels of indirection! By the time you get to five, even experts will be scratching their heads to start with...
Anonymous
6/26/2025, 10:49:26 PM No.105714827
1745786209637692
1745786209637692
md5: 689a875ec051ee28ed62c0803adc596d๐Ÿ”
>>105711325 (OP)
Post yfw every RAM access is a 5 level pointer.
Anonymous
6/26/2025, 10:49:41 PM No.105714829
>>105711325 (OP)
An array of arrays you can't define at compile time.
Anonymous
6/26/2025, 10:59:47 PM No.105714928
>>105713800
No source? I just donโ€™t believe /g/ poster.
Anonymous
6/26/2025, 11:04:09 PM No.105714979
>WHY ARE THERE POINTERS TO POINTERS
Why not?
Anonymous
6/26/2025, 11:09:54 PM No.105715035
most of the time think of it as a pointer to an array that contains pointers. dummy program to show u exactly how it works.
#include <stdio.h>
#include <stdlib.h>

int** two_d_size_n(const int n)
{
int** mem = malloc(n * sizeof(int*));
for (int i = 0; i < n; i++) {
*(mem + i) = malloc(n * sizeof(int));
}
return mem;
}

void fill_2d(int** mem, const int n)
{
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
*(*(mem + i) + j) = i;
}
}
}

void print_2d(int** mem, const int n)
{
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", *(*(mem + i) + j));
}
printf("\n");
}
}

void free_2d(int** mem, const int n)
{
for (int i = 0; i < n; i++) {
free(*(mem + i));
}
free(mem);
}

int main(int argc, char* argv[])
{
/// 10 x 10 matrix
const int size = 10;
int** mem = two_d_size_n(size);
fill_2d(mem, size);
print_2d(mem, size);
free_2d(mem, size);
return 0;
}
Anonymous
6/26/2025, 11:17:31 PM No.105715114
Y'know indexes in an array?
Your memory sticks in your computer are literally just a gigantic 16 or 32GB array. In practice you have a small amount of this array available to your program but it's still all contiguous like a single big array. Declaring arrays or pointers or whatever is just a matter of navigating around your section of this giant array. If you want to skip around to random parts of it to do fancy algorthms or make trees and whatnot, you can use pointers and pointers-to-pointers and pointer arithmetic
Replies: >>105715147
Anonymous
6/26/2025, 11:18:56 PM No.105715133
>>105713800
That is completely negligible compared to anything important you will have to use matrices for
Anonymous
6/26/2025, 11:20:15 PM No.105715147
>>105711466
>>105713490
2D arrays are not arrays of pointers. C is brain damage.

>>105715114
C cripples the mind.
Replies: >>105715160
Anonymous
6/26/2025, 11:21:40 PM No.105715160
>>105715147
If C cripples the mind, (p)OOP injects mercury into it and FP puts a 12 gauge slug through it
Replies: >>105715198
Anonymous
6/26/2025, 11:26:15 PM No.105715198
>>105715160
OOP and FP have a lot of amazing advances for hardware and OS design that are ignored by the mainstream because C programmers are not smart enough to understand any of them.
Replies: >>105715233
Anonymous
6/26/2025, 11:26:46 PM No.105715204
>>105711589
you can resize malloced arrays besides what the other anon said
Anonymous
6/26/2025, 11:29:43 PM No.105715233
>>105715198
>advancing hardware and operating systems via programming paradigms that were literally invented so we could shut the physical reality of a computer (its hardware) out of our minds while programming and use jeet-friendly abstractions instead
You don't know what the sentence you put together even means. Letting turd worlders on the internet was a mistake
Replies: >>105715454
Anonymous
6/26/2025, 11:51:44 PM No.105715454
>>105715233
FP and OOP are easier to use AND closer to the hardware at the same time. C has nothing to do with "the physical reality of a computer (its hardware)" at all. The PDP-11 that C came from used a microcode layer to implement an artificial instruction set with no relationship to the actual hardware. That was not just the PDP-11, but x86, 68k, S/370, and most other processors. They hid the hardware so they could make it easier for assembly programmers who wanted the computer to mimic a person doing things one at a time. Computers like Itanium that don't follow those rules are notoriously hard to write assembly for by hand. FP and OOP expose the physical reality of the computer and allow more freedom in hardware design instead of mimicking a fake sequential processor that pretends it's the 1960s.

OOP is basically how components of a computer communicate. DDR, PCI, USB, SATA, and other protocols are object-oriented. You are sending messages to physical objects, which are abstract and encapsulated (for example, you can replace your hard drive with an SSD and commands would still work because they follow OOP principles). Even your RAM works that way. FP is basically how FPGAs and circuits work at the electrical level, like the Clash language based on Haskell. The internals of the CPU are not "procedural" or "like C" at all, but more like a collection of objects with parts that are functional and parts that hold state and communicate with messages.
https://clash-lang.org/
Anonymous
6/27/2025, 12:01:14 AM No.105715548
>>105711910
Spider-Man meme.jpg
Anonymous
6/27/2025, 12:04:57 AM No.105715582
>>105711325 (OP)
Everything that's not a bitword in a register is a pointer to something. A string array is a pointer to a memory location where a pointer to a memory location is located. Pointers to pointers are just ripping away the abstraction. It can be useful sometimes, and it's good to understand just so you have a more holistic understanding of how the machine actually works.
Replies: >>105715607 >>105715629
Anonymous
6/27/2025, 12:07:31 AM No.105715607
1750574184657098
1750574184657098
md5: 32c788404101452e55fcdc03b30db905๐Ÿ”
>>105715582
>a pointer to a memory location where a pointer to a memory location is located
Anonymous
6/27/2025, 12:09:32 AM No.105715629
>>105715582
>Everything that's not a bitword in a register is a pointer to something. A string array is a pointer to a memory location where a pointer to a memory location is located.
This is not true at all. C dumbed you down so you can't understand how things work anymore. String arrays do not have any pointers anywhere. The array itself might have an address (depending on how it's implemented and how the computer works), but that is not stored in the array.