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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:09:48+00:00 2026-06-08T06:09:48+00:00

Possible Duplicate: Passing multidimensional arrays as function arguments in C I’m trying to use

  • 0

Possible Duplicate:
Passing multidimensional arrays as function arguments in C

I’m trying to use general swap function:

void swap(void **p, void **q){
    void *tmp;
    tmp=*p;
    *p=*q;
    *q=tmp;
}


int main(){
    int M=5;
    int N=6;
    char*w[M][N];

    swap(&w[1][2], &w[2][2]);

    return 0;
    }

Let’s assume that w is initialized already with values, I am wondering only about the way I should send the arguments

I’m trying to figure out how should I send the arguments to swap in this case.

Let’s assume that N=M=2; so I have w looks like {{“stack”, “overflow”},{“best”, “site”}}

  1. swap(w[i][j],w[k][r]) is not the correct option since w[i][j] is reference to an actual string and swap gets **void, where only w[i][j] is a pointer to only *char, so
  2. swap(&w[i][j], &w[k][r]) looks like the right options. since it’s a pointer to char*,
    but I get passing arguments of swap from incompatible pointer type, How come?
  • 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-08T06:09:49+00:00Added an answer on June 8, 2026 at 6:09 am

    You have to cast void** to char*, or char* to void** depending on how you want the code to be written.

    I don’t think C supports any generic-ish way of having a function blind to the type of data it’s working with.

    The typical way of writing a swap function would be for each data type you expect to use it with so you would end up writing separate methods for swapping int*, char*, ect instead of using void pointers.

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

Sidebar

Related Questions

Possible Duplicate: C/C++: Passing variable number of arguments around Imagine I have a function
Possible Duplicate: Passing a Int value to another class I have been trying to
Possible Duplicate: Understanding Python's call-by-object style of passing function arguments I recently came across
Possible Duplicate: C++ passing variables in from one Function to the Next. The Program
Possible Duplicate: passing a pointer by reference in c++ I have a function that
Possible Duplicate: Passing a class (“Country.class”) as an argument in Java I am trying
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)
Possible Duplicate: Passing arguments to JAR which is required by Java Interpreter how to
Possible Duplicate: C/C++: Passing variable number of arguments around I need to put all
Possible Duplicate: How do I use arrays in C++? To put it simply, is

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.