casting a pointer to structure variable

Posted on 1998-06-25
Last Modified: 2010-04-02

struct mystruct{
int num1
int num2
char something[10]

int *mynum = NULL;

How do you cast "*mynum" to my_s.num1?
*mynum = &my_s.num1 (compile warnings)??
Question by:kulesk

Accepted Solution

szetoa earned 50 total points
Comment Utility
If I understand your question correctly, you want to assign
mynum to point to num1 inside the structure mynum.  Try this:

mynum = & my_s.num1;

Now you can assign value to mynum:

*mynum = 1; /* for example */

Hope this helps!!!

Author Comment

Comment Utility

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now