Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Can you tell me what is wrong with the following c code?

struct node {

int count;

struct node *next;

};

int main()

{

int data = 0;

struct node *getdata;

getdata->count = data + 1;

printf("%d", getdata->count);

}

2 Answers

Relevance
  • oops
    Lv 6
    1 decade ago
    Favorite Answer

    No memory has been allocated for the node structure pointed to by getdata. You need to use malloc to do that.

    getdata = (struct node *) malloc(sizeof(struct node));

    I'm not sure if I need to type struct every time before I type node like that. I use c++, and it's not necessary, but I think it is in c.

  • Anonymous
    1 decade ago

    it is not wrong code..

    i complied it but it not gives any error

    out put print as 1

    gcc test.c -o test

    to run

    ./test

    i used cmd

Still have questions? Get your answers by asking now.