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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:41:09+00:00 2026-06-15T13:41:09+00:00

I am having trouble understanding the void* pointer in c. I’ve googled around but

  • 0

I am having trouble understanding the void* pointer in c. I’ve googled around but haven’t really understood how to solve this specific problem:

typedef struct _Test{
   char* c;
}Test;


void method(void* test){
    Test t;
    t = *(Test*)test;
    t.c = "omg";
    printf(t.c); //WORKS
}

int main(){
Test t;
method(&t);
printf(t.c); //NOT WORKING,  prints nothing/random letters

return 0;}

Why? Or rather, best way to fix/get around this issue?

  • 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-15T13:41:10+00:00Added an answer on June 15, 2026 at 1:41 pm

    You are changing the local object t inside method(), after copying main()‘s object t into it. This doesn’t change anything in main()‘s object since you never copy in the other direction.

    You should just access through the pointer and directly change the caller’s object:

    ((Test *) test)->c = "omg";
    

    or, you can make it a bit clearer by using a local pointer of the proper type, which might be what you were trying to do:

    void method(void* test) {
        Test *t = test;
        t->c = "omg";
    }
    

    note that no cast is needed here, since void * automatically converts to Test * in C.

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

Sidebar

Related Questions

Im having trouble understanding this : why Microsoft put Xattribute under Xobject ? they
I am having trouble understanding this java code. I want the image to twinkle
I'm having trouble understanding what causes this difference between C++ and C#. First we
Okay, so recently I've been reading into ninject but I am having trouble understanding
Hi I have a fairly simple program but I am having trouble understanding why
I'm having trouble understanding the value of this in the following example: struct A
This has been bothering me for a while. I'm having a little trouble understanding
I have been looking at this code and I am having trouble understanding the
I'm having trouble understanding some basic memory management principles in C++. This code is
Having trouble understanding how to filter an images table by tag information in a

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.