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

GATE · 2001 · CS · Question 2 subparts

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 210 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…