adplus-dvertising
frame-decoration

Question

What is the output of this C code?
#include <stdio.h>
    struct p
    {
        struct p *next;
        int x;
    };
    int main()
    {
        struct p* p1 = malloc(sizeof(struct p));
        p1->x = 1;
        p1->next = malloc(sizeof(struct p));
        printf("%d\n", p1->next->x);
        return 0;
    }

a.

Compile time error

b.

1

c.

Somegarbage value

d.

0

Posted under C Programming

Answer: (c).Somegarbage value

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this C code?

Similar Questions

Discover Related MCQs

Q. calloc initialises memory with all bits set to zero.

Q. realloc(ptr, size), where size is zero means

Q. function fabs defined math.h header file takes argument of type integer

Q. log(x) function defined in math.h header file is

Q. What type of inputs are accepted by mathematical functions?

Q. In linux, apart from including math header file, the program is successfully executed by which of the following?

Q. Which of the following is not a valid mathematical function?

Q. Which of the following mathematical function requires 2 parameter for successful function call?

Q. Which mathematical function among the following does NOT require int parameters?

Q. sin(x) returns

Q. cos(x) returns

Q. Which among the following mathematical function do not have a “double” return-type?

Q. The function srand(unsigned)

Q. Which is the best way to generate numbers between 0 to 99?

Q. The correct way to generate numbers between minimum and maximum(inclusive) is _________________

Q. rand() and srand() functions are used

Q. What is the return type of rand() function?

Q. Which of the following can be used for random number generation?

Q. Which of the following snippet will effectively generate random numbers?

Q. Which among the following is correct function call for rand and random?