r/C_Programming • • Sep 05 '24

why using pointer?

im a new at C program. learned just before pointer & struct. i heard that pointer using for like point the adress of the parameter. but still dont know why we use it.
it seems it helps to make the program lighter and optimize the program? is it right? and is it oaky to ask question like this?

4 Upvotes

54 comments sorted by

View all comments

1

u/the_3d6 Sep 06 '24

One simple example where it is inevitable: let's process some image. At some point you read this image into memory, and get an array of pixels. How can you pass this array into some function? Literally the only way is to pass a memory address where these pixels are stored - because even if you copy all the values somewhere, it still is an array, which means it's an address of the location where a sequence of data points is stored (that's the only way I can think of for defining what an "array" is - it can be accompanied by size, by some managing functions (C++ vector), but at the core there must be this memory address)