I've always read that "real C programmers use pointers" but as of yet, never had a good reason to use them. Then, last night I thought I had an epiphany. I had a function that had to be able to modify one of three variables. Ah, says I, I finally found a reason to use pointers!
works fine, but you'll need two other assignment statements for the other two colors. If you use a pointer, modifyColor() does need to concern itself which color is changed since no return value is needed and the return type can remain void since no assignment statement is needed. Write your code for changing all three colors, one version using pointer and the other without pointers and tell us about the code size.
Using global variables: Binary sketch size: 466 bytes (of a 32,256 byte maximum)
Using return value assignment: Binary sketch size: 466 bytes (of a 32,256 byte maximum
Using pointers: Binary sketch size: 466 bytes (of a 32,256 byte maximum)
Arrch makes a better point. (Indeed, you can write the pointer and non-pointer code and get the same code size...pretty good compiler.) What Arrch is asking is, what if you want to increment all three colors with one function call:
Arrch:
Which defeats the purpose of having the function in the first place.
I guess I still don't understand the benefit of using global variables and modifyColor(red, green, blue) over calling modifyColor three times, once for each color, assigning the return values.
There are kids in primary school that can't see the use of mathematics. I served in the Army with more than few that by their abilities stopped learning math once they could get change for a ten and hated anyone that went one step further. Show one algebra and they get all wound up about letters where numbers are all anyone needs, then challenge you to a fight to prove who's right.
Explanations would be too long and have already been typed. Pointers are not a small topic to become competent in quickly. Google on "C C++ pointer tutorial" (without the quotes).
Have a look through the standard libraries for commands that return pointers. If you do much with arrays then you should see uses for pointers right there.
But forum posts are no substitute for reading from books or sites and practicing what is shown there. If that's not enough then you need a teacher until you learn to "dress and feed" yourself.