简体   繁体   中英

difference between getch() and (*getch)()

I want to know the difference between these two statements....

  1. ch=getch();
  2. ch=(*getch)();

both statements return the same vale in "ch". I am possibly wrong but I think the second statement is used when we want to speed up the execution of the program.

They do exactly the same thing.

There's no difference whatsoever.

It's possible that getch() is implemented as a macro (in addition to its implementation as an actual function). If so,

ch=getch();

will invoke the macro, and

(*getch)()

will bypass the macro definition and call the actual function. In that case, getch() is likely to be faster.

And in practice, at least for the implementations I've tried, getch() isn't implemented as a macro, and the two versions are identical.

In either case, (*getch)() is obfuscation for no good reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM