Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
void (*ptr)() defines a function pointer. It says that ptr is a pointer to a function. But that function must have a void return type, and take an arbitrary number of parameters (that's what the em...
Answer
#4: Post edited
`void (*ptr)()` defines a function pointer. It says that `ptr` is a pointer to a function. But that function must have a `void` return type, and take no parameters (that's what the empty parentheses defines).Then, `ptr = PrintHello` assigns the `PrintHello` function to the `ptr` pointer (and it works because `PrintHello` matches the signature: it has a `void` return type and takes no parameters). So, now `ptr` is pointing to `PrintHello`.- Finally, `ptr()` is calling the function that `ptr` points to (in this case, `PrintHello`). It has the same effect as calling `PrintHello()`, and the parentheses are needed because it's a function call. But the function takes no parameters, thus the empty parentheses.
- `void (*ptr)()` defines a function pointer. It says that `ptr` is a pointer to a function. But that function must have a `void` return type, and take an arbitrary number of parameters (that's what the empty parentheses defines).
- Then, `ptr = PrintHello` assigns the `PrintHello` function to the `ptr` pointer (and it works because `PrintHello` matches the signature: it has a `void` return type). So, now `ptr` is pointing to `PrintHello`.
- Finally, `ptr()` is calling the function that `ptr` points to (in this case, `PrintHello`). It has the same effect as calling `PrintHello()`, and the parentheses are needed because it's a function call. But the function takes no parameters, thus the empty parentheses.
#3: Post edited
- `void (*ptr)()` defines a function pointer. It says that `ptr` is a pointer to a function. But that function must have a `void` return type, and take no parameters (that's what the empty parentheses defines).
Then, `ptr = PrintHello` assigns the `PrintHello` function to the `ptr` pointer (because `PrintHello` matches the signature: it has a `void` return type and takes no parameters). So, now `ptr` is pointing to `PrintHello`.- Finally, `ptr()` is calling the function that `ptr` points to (in this case, `PrintHello`). It has the same effect as calling `PrintHello()`, and the parentheses are needed because it's a function call. But the function takes no parameters, thus the empty parentheses.
- `void (*ptr)()` defines a function pointer. It says that `ptr` is a pointer to a function. But that function must have a `void` return type, and take no parameters (that's what the empty parentheses defines).
- Then, `ptr = PrintHello` assigns the `PrintHello` function to the `ptr` pointer (and it works because `PrintHello` matches the signature: it has a `void` return type and takes no parameters). So, now `ptr` is pointing to `PrintHello`.
- Finally, `ptr()` is calling the function that `ptr` points to (in this case, `PrintHello`). It has the same effect as calling `PrintHello()`, and the parentheses are needed because it's a function call. But the function takes no parameters, thus the empty parentheses.
#2: Post edited
- `void (*ptr)()` defines a function pointer. It says that `ptr` is a pointer to a function. But that function must have a `void` return type, and take no parameters (that's what the empty parentheses defines).
- Then, `ptr = PrintHello` assigns the `PrintHello` function to the `ptr` pointer (because `PrintHello` matches the signature: it has a `void` return type and takes no parameters). So, now `ptr` is pointing to `PrintHello`.
Finally, `ptr()` is calling the function that `ptr` points to (in this case, `PrintHello`).
- `void (*ptr)()` defines a function pointer. It says that `ptr` is a pointer to a function. But that function must have a `void` return type, and take no parameters (that's what the empty parentheses defines).
- Then, `ptr = PrintHello` assigns the `PrintHello` function to the `ptr` pointer (because `PrintHello` matches the signature: it has a `void` return type and takes no parameters). So, now `ptr` is pointing to `PrintHello`.
- Finally, `ptr()` is calling the function that `ptr` points to (in this case, `PrintHello`). It has the same effect as calling `PrintHello()`, and the parentheses are needed because it's a function call. But the function takes no parameters, thus the empty parentheses.
#1: Initial revision
`void (*ptr)()` defines a function pointer. It says that `ptr` is a pointer to a function. But that function must have a `void` return type, and take no parameters (that's what the empty parentheses defines). Then, `ptr = PrintHello` assigns the `PrintHello` function to the `ptr` pointer (because `PrintHello` matches the signature: it has a `void` return type and takes no parameters). So, now `ptr` is pointing to `PrintHello`. Finally, `ptr()` is calling the function that `ptr` points to (in this case, `PrintHello`).