Consider the following three C functions: [P1] int *g(void) { int x = 10;…

PYQ GATE 2001

Consider the following three C functions:

[P1]
int *g(void)
{
   int x = 10;
   return &x;
}

[P2]
int *g(void)
{
   int *px;
   *px = 10;
   return px;
}

[P3]
int *g(void)
{
   int *px;
   px = (int *) malloc(sizeof(int));
   *px = 10;
   return px;
}

Which of the above three functions are likely to cause problems with pointers?

  1. A.

    Only P3

  2. B.

    Only P1 and P3

  3. C.

    Only P1 and P2

  4. D.

    P1, P2 and P3

Attempted by 266 students.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…