How to access members through a void pointer

前端 未结 4 1457
我寻月下人不归
我寻月下人不归 2021-01-15 20:29

Started by trying to write a small program to translate basic arithmetic into English, I end up building a binary tree(which is inevitably very unbalanced) to represent the

4条回答
  •  一整个雨季
    2021-01-15 20:51

    Just convert p to the relevant pointer type:

    s *a = p;
    
    a->i1 = 42;
    a->i2 = 31;
    

    or

    ((s *) p)->i1 = 42;
    ((s *) p)->i2 = 31; 
    

提交回复
热议问题