Structs and pointers
        Posted  
        
            by 
                user1763861
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1763861
        
        
        
        Published on 2012-12-02T04:49:24Z
        Indexed on 
            2012/12/02
            5:03 UTC
        
        
        Read the original article
        Hit count: 162
        
I have a few questions about structs and pointers
For this struct:
typedef struct tNode_t {
    char *w;
} tNode;
How come if I want to change/know the value of *w I need to use t.w = "asdfsd" instead 
of t->w = "asdfasd"?
And I compiled this successfully without having t.w = (char *) malloc(28*sizeof(char));
in my testing code, is there a reason why tt's not needed?
Sample main:
int main()
{
    tNode t;
    char w[] = "abcd";
    //t.word = (char *) malloc(28*sizeof(char));
    t.word = w;
    printf("%s", t.word);
}
Thanks.
© Stack Overflow or respective owner