Programming for Problem Solving (3110003) MCQs

MCQs of Pointers

Showing 21 to 25 out of 25 Questions
21.
What is the output?

void main()
{
    int arr[5] = {1,5,9,13,18};
    int *p = &arr[2];
    int *q = &arr[4];
    printf("%d",*q-*p);
}

(a) 8
(b) 9
(c) -8
(d) -9
Answer:

Option (b)

22.
What is the output?

void main()
{
    int arr[5] = {1,5,9,13,18};
    int *p = &arr[1];
    int *q = &arr[4];
    printf("%d",q-p);
}

(a) 6
(b) 12
(c) 3
(d) 13
Answer:

Option (c)

23.
What is the output?

void fun(int *ptr)
{
    *ptr = 30;
}
void main()
{
  int y = 20;
  fun(&y);
  printf("%d", y);
}

(a) 20
(b) 30
(c) Compiler error
(d) Runtime error
Answer:

Option (b)

24.
What is the output?

void test(int * , int *);
void main()
{
  int a = 5 , b = 6;
  test(&a,&b);
  printf("%d, %d",a,b);
}
void test(int *p, int *q)
{
  *p = *p * *q;
  *q = *p / *q;
  *p = *p / *q;
}

(a) 30, 5
(b) 6, 5
(c) 5, 6
(d) None of these
Answer:

Option (b)

25.
What is the output?

void test(int *a, int *b) 

  a = b; 
  *a = 15; 

int main() 

  int x = 10, y = 20; 
  test(&x, &y); 
  printf("%d, %d", x, y);
}

(a) 15, 15
(b) 10, 15
(c) 10, 20
(d) 15, 20
Answer:

Option (b)

Showing 21 to 25 out of 25 Questions