Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6607439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:30:12+00:00 2026-05-25T19:30:12+00:00

Possible Duplicate: How does dereferencing of a function pointer happen? void myprint(char* x) {

  • 0

Possible Duplicate:
How does dereferencing of a function pointer happen?

  void myprint(char* x) {
      printf("%s\n", x); 
  }

  int main() {
     char* s = "hello";
     void (*test)(char*);
     void (*test2)(char*);

     test = myprint;
     test2 = &myprint;

     test(s);
     (*test)(s);
     test2(s);
     (*test2)(s);

  }

Can anyone explain to me why all of the above code is valid? “hello” is printed four times. By applying the function pointer, is it implicitly derefenced? Basically I want to know how function pointers are actually stored, because the above is kind of confusing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:30:13+00:00Added an answer on May 25, 2026 at 7:30 pm

    This is just a quirk of C. There’s no other reason but the C standard just says that dereferencing or taking the address of a function just evaluates to a pointer to that function, and dereferencing a function pointer just evaluates back to the function pointer.

    This behavior is (thus obviously) very different from how the unary & and * operators works for normal variables.

    So,

    test2 = myprint;
    test2 = &myprint;
    test2 = *myprint;
    test2 = **********myprint;
    

    All just do exactly the same, gives you a function pointer to myprint

    Similarly,

    test2(s);
    (*test2)(s);
    (***********test2)(s);
    

    Does the same, call the function pointer stored in test2. Because C says it does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How does dereferencing of a function pointer happen? If we have void
Possible Duplicate: How does dereferencing of a function pointer happen? Hi All, Why these
Possible Duplicate: does c++ standard prohibit the void main() prototype? Why is C++ not
Possible Duplicate: Where does ‘Hello world’ come from? What was the first Hello World
Possible Duplicate: Where does ‘Hello world’ come from? Hello world! is the most commonly
Possible Duplicate: What does the tilde (~) mean in C#? class ResourceWrapper { int
Possible Duplicate: Why does printf not flush after the call unless a newline is
Possible Duplicate: What does this “(function(){});”, a function inside brackets, mean in javascript ?
Possible Duplicate: Does the size of an int depend on the compiler and/or processor?
Possible Duplicate: why does initializing subclasses require calling the super class's same init function?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.