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

  • Home
  • SEARCH
  • 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 8817517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:52:05+00:00 2026-06-14T04:52:05+00:00

One of my teachers use this type declaration: typedef void (*SortFunction)(int a[], int n);

  • 0

One of my teachers use this type declaration:

typedef void (*SortFunction)(int a[], int n);

to create a type that can hold a pointer to a function
and that can be used to call that function later on in a program.

I also know that to pass a function as a parameter you have to
wrap the function name in parenthesis and wrap the function’s
parameters in parenthesis after the function name as well like so

function someFunction( (anotherfunction)(type arg1, type arg2,...)){
  ...
} 

What I want to know is why must you wrap a function in parenthesis like this? is this a built in function of most c++ compilers or is it simply a trick that we programmers use
in order to enable functions as arguments within our code? also, why does “SortFunction”
in the typedef statement need to be referenced, why can’t the variable you use to utilize SortFunction just hold the function instead of pointing to it?

  • 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-06-14T04:52:07+00:00Added an answer on June 14, 2026 at 4:52 am

    There’s nothing special about function arguments. Whenever you declare a function pointer (as a local variable, global variable, class member variable, function parameter, typedef, etc.), it’s always declared like so:

    return_type (*var_name)(T1 param1, T2 param2, /* etc. */ );
    //           ^
    //           |
    // This * is very important!
    

    Where var_name is the name of the function pointer variable. The reason the parentheses are needed around *var_name is due to operator precedence: without the parentheses, the * (indicating that something’s a pointer) would match with the function’s return type, and instead you’d get something like a return type of int* (pointer to int) instead of plain int.

    You can’t pass a function as an argument because functions are not first-class objects in C and C++. The only way to pass a function is my passing a pointer to the function.

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

Sidebar

Related Questions

One can say a type parameter T must have a specific supertype S_1: class
I've four kinds of user (Customer, Admin, Manager, teacher) that can use my future
I have models in project that use more than one table to select. How
A sysadmin teacher told me one day that I should learn to use make
I'm building a system that involves users and teachers. In this particular system however
I have a problem and can't solve it alone. My teacher gives me one
One of the neat characteristics of UTF-8 is that if you compare two strings
The site I'm working on involves teachers creating student objects. The teacher can choose
I was watching the Lullabot jQuery video and in it one of the teachers
The Unix philosophy teaches that we should develop small programs that do one thing

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.