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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:00:35+00:00 2026-06-08T08:00:35+00:00

Today when I was reading others’ code, I saw something like void *func(void* i);

  • 0

Today when I was reading others’ code, I saw something like void *func(void* i);, what does this void* mean here for the function name and for the variable type, respectively?

In addition, when do we need to use this kind of pointer and how to use 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-08T08:00:38+00:00Added an answer on June 8, 2026 at 8:00 am

    A pointer to void is a “generic” pointer type. A void * can be converted to any other pointer type without an explicit cast. You cannot dereference a void * or do pointer arithmetic with it; you must convert it to a pointer to a complete data type first.

    void * is often used in places where you need to be able to work with different pointer types in the same code. One commonly cited example is the library function qsort:

    void qsort(void *base, size_t nmemb, size_t size, 
               int (*compar)(const void *, const void *));
    

    base is the address of an array, nmemb is the number of elements in the array, size is the size of each element, and compar is a pointer to a function that compares two elements of the array. It gets called like so:

    int iArr[10];
    double dArr[30];
    long lArr[50];
    ...
    qsort(iArr, sizeof iArr/sizeof iArr[0], sizeof iArr[0], compareInt);
    qsort(dArr, sizeof dArr/sizeof dArr[0], sizeof dArr[0], compareDouble);
    qsort(lArr, sizeof lArr/sizeof lArr[0], sizeof lArr[0], compareLong);
    

    The array expressions iArr, dArr, and lArr are implicitly converted from array types to pointer types in the function call, and each is implicitly converted from “pointer to int/double/long” to “pointer to void“.

    The comparison functions would look something like:

    int compareInt(const void *lhs, const void *rhs)
    {
      const int *x = lhs;  // convert void * to int * by assignment
      const int *y = rhs;
    
      if (*x > *y) return 1;
      if (*x == *y) return 0;
      return -1;
    }
    

    By accepting void *, qsort can work with arrays of any type.

    The disadvantage of using void * is that you throw type safety out the window and into oncoming traffic. There’s nothing to protect you from using the wrong comparison routine:

    qsort(dArr, sizeof dArr/sizeof dArr[0], sizeof dArr[0], compareInt);
    

    compareInt is expecting its arguments to be pointing to ints, but is actually working with doubles. There’s no way to catch this problem at compile time; you’ll just wind up with a missorted array.

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

Sidebar

Related Questions

I came across this code today whilst reading Accelerated GWT (Gupta) - page 151
Today i was reading about pure function, got confused with its use: A function
While reading proggit today, I came upon this comment in a post about how
I was reading this today: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#default-parameter-values and I can't seem to understand what's happening
I was reading Joel On Software today and ran across this quote : Without
As you can see by reading my other thread today here , I'm having
Today,when I was reading the MSDN,I encountered the following codes: void draw( int I,
Today out of curiosity, i tried something very weird: The Code : int num
I was reading today about OOCSS which says by using that approach have 2
Today I was reading Floyd's algorithm of detecting loop in a linked list. I

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.