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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:05:37+00:00 2026-05-14T14:05:37+00:00

I have written this qsort: void qsort(void *a[],int low,int high, int (*compare)(void*,void*)); When I

  • 0

I have written this qsort:

void qsort(void *a[],int low,int high, int (*compare)(void*,void*));

When I call this on

char *strarr[5];

It says invalid conversion from char** to void**. Why this is wrong?

This is the code:

#include<cstdlib>
#include<cstdio>
#include<iostream>

using namespace std;

inline void strswap(void *a,void *b) {
    char *t=*(char**)a;
    *(char**)a=*(char**)b;
    *(char**)b=t;
}

int strcompare(void *a, void *b) {
    return strcmp(*(char**)a,*(char**)b);
}

void qsort1(void *a[],int low,int high, int (*compare)(void*,void*), void (*swap)(void*,void*)) {
    if(low>=high)
        return;
    int q=low-1;
    for(int i=low;i<=high-1;i++)
        if((*compare)(&a[i],&a[high]) < 0)
            swap(&a[i],&a[++q]);
    swap(&a[high],&a[++q]);
    qsort1(a,low,q-1,compare,swap);
    qsort1(a,q+1,high,compare,swap);
}

int main() {
    const  int n=3;
    //int a[n]={4,6,8,12,10,9,8,0,24,3};
    char *strarr[5]={"abcd","zvb","cax"};
    qsort1(strarr,0,n-1,strcompare,strswap);
    for(int i=0;i<n;i++)
        cout << strarr[i] << " ";
    cout << endl;
    return 0;
}
  • 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-14T14:05:38+00:00Added an answer on May 14, 2026 at 2:05 pm

    An implicit conversion from any pointer type to void * is allowed, because void * is a defined to be a pointer type that has a sufficient range that it can represent any value that any other pointer type can. (Technically, only other object pointer types, which excludes pointers to functions).

    This does not mean that void * has the same size or representation as any other pointer type, though: Converting a pointer from another pointer type to a void * does not necessarily leave the underlying representation unchanged. Converting from double * to void * is just like converting from double to int – it has to happen in full view of the compiler, you can’t hide that conversion behind the compiler’s back.

    So this implies that while void * is a generic pointer, void ** is not a generic pointer-to-pointer. It’s a pointer to void * – a void ** pointer should only ever point to real void * objects (whereas void * itself can point to anything).

    This is why there’s no implicit conversions between type ** and void ** – it’s for the same reason that there’s no implicit conversions between double * and int *.

    Now, there is one special case: for historical reasons, char * is guaranteed to have the same size, representation and alignment requirements as void *. This means that conversions between char ** (in particular) and void ** are actually OK, as an exception to the general rule. So in your particular case, your code is correct if you add a cast to void ** when you pass strarr to qsort1().

    However, your qsort1() is only defined to correctly work on arrays of void * or char * (including unsigned char * etc.). You can’t use it to sort an array of double * pointers, for example (although it would actually work on most common environments today).

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

Sidebar

Related Questions

i have written this structure: struct bmpheader { unsigned char magic[2]; unsigned int fsize;
I have written this piece of code: namespace { void SkipWhiteSpace(const char *&s) {
I have written this code which is simple #include <stdio.h> #include <string.h> void printLastLetter(char
I have written this code outside all functions: int l, k; for (l =
I have written this code in C# for WP7 : public void btn_handler(object sender,
I have written this piece of code public class Test{ public static void main(String[]
I have written this code: public void reloadDefConfig(File filepath, String fileInJar) { File configFile
I have written this function in C: void *PWNRetain(void *object) { PWNObject *obj =
have written this little class, which generates a UUID every time an object of
I have written this code inside a servlet to delete certain records from three

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.