Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Question on Unions in C

Name: Anonymous 2012-06-24 2:12

So, I know that a pointer is a variable that stores a memory address (basic 4 or 8 bytes). If I place a pointer in a Union type, does the memory address stored by the pointer share the same memory space as the other types, or does the data at the memory address share the same memory?

Or, in other words, if I union a double and a char*, will I memory leak/segfault if I assign the double to anything?

Name: Anonymous 2012-06-24 4:22

Is it really that difficult to just test it yourself?


#include <stdio.h>

typedef union {
    long x;
    long* y;
} dickbutt;

int main()
{
    dickbutt shitdick;
    shitdick.x = 0x23;
    printf("0x%x", shitdick.y); // outputs 0x23
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List