How can we assign a pointer to a function? const char* function_name(), here what exactly does the pointer point to?
Thanks.
How can we assign a pointer to a function? const char* function_name(), here what exactly does the pointer point to?
Thanks.
In this example, const char * is the type of the return result.
size_t strlen( const char *);
size_t is the return type
const char * is the parameter type.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
size_t here is an user-defined return type I believe. How do we implement it? Can you help me with an example? Thanks.
size_t is a type defined by the standard. I think the idea is to solve problems similar to this:
char x[y];
You might think y is an integer. But is it really? What if y is -1? What if y is a number outside the range of valid addressable areas on your computer?
Defining the type as size_t solves these problems because it is guaranteed to work in these situations. But really the bottom line is that if a function returns size_t, then you must either:
a. assign it to a size_t type variable
b. guarantee for yourself that the value returned actually does fit into the variable type you are assigning to
More info:
int - What is size_t in C? - Stack Overflow
Thank YOU.