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.
GoForSmoke:
But forum posts are no substitute for reading from books or sites and practicing what is shown there.
That's just it... I've been reading C books and sites for years now. I guess I haven't been reading the right books and sites since it seems like for every book or site where a pointer is used, it's not the only way to skin that particular cat.
Don't think I'm hating on C or pointers because I don't understand them. But it's looking to me like pointers are a lot like recursion (if you're smart enough to do recursion, then by definition you're smart enough to find a way to do the same thing without recursion).
I'll admit using pointers for function calls dealing with strings and structures appear to be a good use of pointers, but it seems to me that's mainly just a band-aid for C's inability to return a string or struct from a function.
Some data structures are easier to implement with pointers. Consider linked lists & trees, or indeed anything that uses dynamic memory allocation. Not that you'd really want to use those things in an Arduino context with so little RAM.