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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:58:02+00:00 2026-06-15T14:58:02+00:00

i want to pass a function within function by reference in c.They both use

  • 0

i want to pass a function within function by reference in c.They both use the same parameters.This is the code

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void AtoB(int *A, int *B, int *C, int n,int *h1,int *h2,int *h3 );
void AtoC(int *A, int *B, int *C, int n,int *h1,int *h2,int *h3 );
void BtoC(int *A, int *B, int *C, int n,int *h1,int *h2,int *h3 );
void function2(int *A, int *B, int *C, int n);

int main(){
int n;
int e;
int h3=1;
int h2=1;
int h1=0;
int min;
int *A;
int *B;
int *C;



printf("Give me the number of disks:");
scanf("%d",&n);
A = (int *) calloc(n,sizeof(int));
B = (int *) calloc(n,sizeof(int));
C = (int *) calloc(n,sizeof(int));
min=pow(2,n)-1;
for (e=0;e<n;e++){
  A[e]=e+1;
}

if (n%2==0){
 for (e=0;e<min/3;e++){
   AtoB(A,B,C,n,&h1,&h2,&h3);



 }



 }



























free(A);free(B);free(C);

 return 0;
}


int function1(int Z[],int n){
int j,i,k,a;
for (i=0;i<n;i++){
 k=n-Z[i];
  for (j=0;j<n;j++){
   if(k==j){
    for(a=0;a<2*Z[i]-1;a++){
    printf("%d",Z[i]);
    }
   }
   else if((j==n-1)&&(Z[i]==0)){
    printf("|");
   }
   else{
   printf(" ");
   }
   }
printf("\n");

 }for(i=0;i<2*n-1;i++){
 printf("-");
}
printf("\n\n");
return 0;
}
void function2(int A[],int B[],int C[],int n){

    printf("A\n");
    function1(A,n);
    printf("B\n");
    function1(B,n);
    printf("C\n");
    function1(C,n);
}

void AtoB(int A[],int B[],int C[],int n,int *h1,int  *h2,int *h3){
     if (B[n-1]==0){
     printf("A->B\n");
     B[n-1]=A[*h1];
     A[*h1]=0;
     *h1=*h1+1;
     function2(A,B,C,n);}
     else if (A[n-1]==0){
     printf("A->B\n");
     A[0]=B[n-*h2];
     B[n-*h2]=0;
     *h2=*h2-1;
     function2(A,B,C,n);

    }
AtoC(A,B,C,n,&h1,&h2,&h3);


}

void AtoC(int A[], int B[], int C[], int n,int *h1,int *h2,int *h3 ){



}

The program must solve hanoi tower while showing the tower structure.

I am getting error: passing argument 5 of ‘AtoC’ from incompatible pointer type.Thanks in advance.

  • 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-15T14:58:03+00:00Added an answer on June 15, 2026 at 2:58 pm

    You can’t do like that, In AtoB function you have declared h1 as a pointer and in AtoC function you are passing address of that pointer. Both functions should have same declaration like that *h1,*h2,*h3.

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

Sidebar

Related Questions

i want to pass a function within function by reference in c.They both use
If I want to run a function within another function I can pass in
I want to pass id1, id2 and id3 through the function below. This works
I want to pass a function to another function. I think functions being passed
I want to pass a member function of class A to class B via
I have a function that i want to pass as a parameter function myFun(){
I have a function that I want to pass an argument, market, to the
I want to pass an array of arbitrary struct pointers and a comparison function
I want to pass a variable as text or somehow to make above function
I want to pass a property list of a class to a function. with

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.