Struct help...

This is a discussion on Struct help... within the C Programming forums, part of the General Programming Boards category; Hello World!
(struct sockaddr *)&my_addr
What does this line do?... I am still trying to learn C...

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

Green = Tells the compiler it's a castRed = Tells the compiler what you're casting toBlue = Address of operator: takes the address of a variableOrange = Tells the compiler what you want to take the address of

The thing is that your struct is just a block of raw memory in the eyes of the CPU or the computer.
The compiler just manages that memory for you.
And because memory is "raw," there are actually no "types". Your struct is just a piece of memory. The compiler keeps track of its type.
But you can tell the compiler that it's another type than it is. It works because it's just a block of memory.

The thing is that your struct is just a block of raw memory in the eyes of the CPU or the computer.
The compiler just manages that memory for you.
And because memory is "raw," there are actually no "types". Your struct is just a piece of memory. The compiler keeps track of its type.
But you can tell the compiler that it's another type than it is. It works because it's just a block of memory.

So i places the value of &my_addr in the struct sockaddr memory block.... right? and whats i the "*" good for?

Again, because it's a pointer.
It simply tells the compiler to treat the data at the address in the pointer as something else.
There's a difference:

Code:

float f = 1.0f;
int n = (int)f; /* Converts the data inside f to an integer - result is 1. */
int* pN = (int*)&f; /* Tells the compiler to treat the data at the address where f resides as
an int. The result will not be 1, but something much else. */

Again, because it's a pointer.
It simply tells the compiler to treat the data at the address in the pointer as something else.
There's a difference:

Code:

float f = 1.0f;
int n = (int)f; /* Converts the data inside f to an integer - result is 1. */
int* pN = (int*)&f; /* Tells the compiler to treat the data at the address where f resides as
an int. The result will not be 1, but something much else. */

Look, in all honesty, you're asking questions for things that require way more knowledge than you have at the moment and will likely have for some time. You need to buckle down and get a book or a tutorial and start from the basics and work your way up.