Search code examples
cpointersstructure

return a pointer to structure taking no parameters


I prepare for my C test and found a question where I need to write a declaration in C:

val is declared as returning a pointer to struct s and taking no parameters.

I did it like that, but not sure if I am correct:

struct s (* val) (void)

Solution

  • If it is a function pointer you're aiming for, it should be

    struct s *(* val) (void) 
    

    If it is a function prototype, it should be

    struct s *val (void)