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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:26:48+00:00 2026-06-14T15:26:48+00:00

I tried both – C and C++ and both work fine. I’m kinda new

  • 0

I tried both – C and C++ and both work fine.

I’m kinda new to function pointers and here’s a simple code, that surprised me:

#include <assert.h>
void sort( int* arr, const int N );

int main () 
{
    int arr1[] = { 1, 5, 2, 6, 2 }; 
    int arr2[] = { 1, 5, 2, 6, 2 }; 

    void (*sort_ptr)( int*,  const int) = sort;

    sort_ptr( arr1, 5 );
    (*sort_ptr)( arr2, 5 );

    assert( arr1[0] == 1 && arr1[1] == 2 && arr1[2] == 2 && 
            arr1[3] == 5 && arr1[4] == 6 );
    assert( arr2[0] == 1 && arr2[1] == 2 && arr2[2] == 2 && 
            arr2[3] == 5 && arr2[4] == 6 );

    return 0;
}

void sort( int* arr, const int N )
{
    // sorting the array, it's not relevant to the question
}

So, what’s the difference between

sort_ptr( arr1, 5 );

and

(*sort_ptr)( arr2, 5 );

Both seems to work (no errors, no warnings, sorted arrays) and I’m kinda confused. Which one is the correct one or they both are correct?

  • 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-14T15:26:49+00:00Added an answer on June 14, 2026 at 3:26 pm
    sort_ptr( arr1, 5 );
    

    and

    (*sort_ptr)( arr2, 5 );
    

    Both are correct. In fact, you can put as many asterisks you want and they are all correct:

    (*****sort_ptr)( arr2, 5 );
    

    The name of function decays to a pointer to a function. So dereferencing it repeatedly is going to produce the same pointer.

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

Sidebar

Related Questions

I tried both the Intent-receiver and the onKeyDown Method. Both work fine for most
I tried both JRSwizzle, and MethodSwizzle. They compile fine on the simulator but throw
I am trying to run code on several cores (I tried both the snow
I created a simple test with SendKeys, and tried both SendWait and Send. Private
I tried with both the web install platform and manually but both don't work.
Code snippet to follow. I have a struct (example code has class, tried both,
I tried to change the HTML form, input type file. Here is my code:
This seems like it ought to be simple, but I've tried both try {}
Does anyone have any insights regarding compiling Ruby code for Windows? I've tried both
I have a very simple game using Xcode v4.2.1, Cocos2d v5.0.1. I've tried both

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.