Not Using '&' When Passing A Pointer
"some_function" receives a pointer to a character - it's defined as follows:
void some_function(char *c);
From what I learned, when we want to call "some_function" - we should pass an to the argument using the '&' operator:
But I've seen working examples where "some_function" directly receives a string:
How does it work? Is this practice recommended?
In C all literal strings are really arrays of (read-only) characters, including the ending null-terminator.
And as all arrays in C, they can decay to a pointer to their first element.
Which means all string literals can be used whenever a
char * is expected.
It's similar (but not equivalent) to having:
char some_string = "some string"; some_function(some_string); // equal to some_string(&some_string)
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page