Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a function pointer without parenthesis

I have this code:

#include <stdio.h>

int getAns(void);
int num;

int main() 
{
    int (*current_ans)(void);
    current_ans = &getAns;
    // HERE
    printf("%d", current_ans());    

}

int getAns()
{
    return num + 3;
}

However, is it possible to have something in the // HERE spot that allows the next line to be printf("%d", current_ans); which accesses getAns() in a roundabout way?

like image 220
827 Avatar asked Jun 22 '26 02:06

827


1 Answers

Though I agree with pierr's answer, the

#define current_ans current_ans()

will make the code very much unreadable

like image 56
Alphaneo Avatar answered Jun 23 '26 15:06

Alphaneo