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

  • Home
  • SEARCH
  • 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 7840921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:58:03+00:00 2026-06-02T15:58:03+00:00

I am passing in a void pointer that was converted from a struct into

  • 0

I am passing in a void pointer that was converted from a struct into a function topTwo. When I cast it back and try to get data from the struct I get the address instead. What am I doing wrong?
In this function I am trying to get localStruct->number to return 1 and instead it is returning the address.

 void  *topTwo(void *p)
 {
  struct Variables * localStruct;
  localStruct= (struct Variables *) p;
  cout<<localStruct->number<<endl;
  int  z = long(localStruct->number);
  cout<<z<<endl;
}

Here is the struct

struct Variables{
 int largestNum;
 int secondLargestNum;
 int number;
};

Here is the main function that passes in the data.

int main() 
{
    Variables *vars;
    vars= new struct Variables();
    vars->largestNum=0;
    vars->secondLargestNum=0;
    vars->number=0;
    pthread_t  tid[5];
    for(int  i=0; i<5; i++)
    {                                   
       vars->number=i;
       cout<<vars->number<<endl;                                               
       void * sVoid;
       sVoid = (void *) &vars;
       pthread_create(&tid[i], NULL, topTwo,(void *) sVoid);
       pthread_join(tid[i], NULL);
    }
 }
  • 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-02T15:58:05+00:00Added an answer on June 2, 2026 at 3:58 pm

    Change:

    sVoid = (void *) &vars;  // this is a `struct Variables**`
    

    to:

    sVoid = (void *) vars;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am passing a vector pointer to another function which pushes data using that
I have a function that takes pointer to pointer to struct. struct ABC; void
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast and
I have grep function in C( embedded programming ) that takes a void pointer
I don't understand why passing a pointer to a function doesn't change the data
I have a C struct that contains a function pointer. Now, I have used
Say I have a function that receives a byte array: void fcn(byte* data) {
What is the difference between passing-by-reference and using the C pointer notation? void some_function(some_type&
passing post data using cURL requires that the name of the input. However, I
Say I have a function that takes a const reference to a pointer... Example:

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.