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 6719099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:03:09+00:00 2026-05-26T09:03:09+00:00

This is a rather simple question that is making me a bit curious. Consider

  • 0

This is a rather simple question that is making me a bit curious. Consider the following code snippet:

#include <iostream>

int three()
{
    return 3;
}

void foo(int func(void))
{
    std::cout << func() << std::endl;
}

void bar(int (*func)(void))
{
    std::cout << func() << std::endl;
}

int main()
{
    foo(three);
    bar(three);
    return 0;
}

// output:
// 3
// 3

As you can see, we have two functions that take another function as their only argument. However, the function prototypes for them differ. Mainly, we have void foo(int func(void)) and void bar(int (*func)(void)). At first glance, it looks like foo is taking the function itself, and bar is taking a pointer to a function.

However, they both produce the exact same results, and have the exact same body, and are called in exactly the same manner.

My question is, is there an actually hidden difference between foo and bar? Is this simply an optional syntax in C++? Is one of the two cases considered “bad style” in C++?

If my compiler is a contributing factor, I’m using Visual Studio 2010.

  • 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-26T09:03:09+00:00Added an answer on May 26, 2026 at 9:03 am

    There is no difference: the types of foo and bar are the same: int(int(*)()).

    There is no such thing as a function-type parameter: when a parameter appears with the function type syntax (like int func(void)), it is transformed into the corresponding pointer-to-function type (like int (*func)(void)).

    The transformation is similar to how a parameter declared with array syntax (e.g. int a[]) is transformed into the corresponding pointer type (int* a).

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

Sidebar

Related Questions

I have this rather simple question about Scala. Given that i have to following
I always stumble upon this (rather simple question) when making e.g. Wordpress blogs. Should
I'm pretty sure this is a rather simple and straightforward question for anyone that
This is a very basic or rather simple question. In my code, I'm using
I searched google but couldn't find an answer to this rather simple question. I
I'm rather new to WPF, so maybe this is a simple question. I have
This is a rather simple question and I'm sure it's not to hard, but
This is a (hopefully) really simple question - I have been told recently that
This is a rather simple question, I have a base class which implements common
Simple question really. As part of some data structure changes that I've been making,

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.