250+ TOP MCQs on Pointers and Function Arguments and Answers

C MCQs (multiple choice questions) on “Pointers and Function Arguments”. One shall practice these MCQs to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our multiple choice questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C multiple choice questions on “Pointers and Function Arguments” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     void foo(int*);
  3.     int main()
  4.     {
  5.         int i = 10;
  6.         foo((&i)++);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         printf("%dn", *p);
  11.     }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
Answer: c
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     void foo(int*);
  3.     int main()
  4.     {
  5.         int i = 10, *p = &i;
  6.         foo(p++);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         printf("%dn", *p);
  11.     }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault
Answer: a
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     void foo(float *);
  3.     int main()
  4.     {
  5.         int i = 10, *p = &i;
  6.         foo(&i);
  7.     }
  8.     void foo(float *p)
  9.     {
  10.         printf("%fn", *p);
  11.     }

a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
Answer: b
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 97, *p = &i;
  5.         foo(&i);
  6.         printf("%d ", *p);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         int j = 2;
  11.         p = &j;
  12.         printf("%d ", *p);
  13.     }

a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash
Answer: a
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 97, *p = &i;
  5.         foo(&p);
  6.         printf("%d ", *p);
  7.         return 0;
  8.     }
  9.     void foo(int **p)
  10.     {
  11.         int j = 2;
  12.         *p = &j;
  13.         printf("%d ", **p);
  14.     }

a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash
Answer: a
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 11;
  5.         int *p = &i;
  6.         foo(&p);
  7.         printf("%d ", *p);
  8.     }
  9.     void foo(int *const *p)
  10.     {
  11.         int j = 10;
  12.         *p = &j;
  13.         printf("%d ", **p);
  14.     }

a) Compile time error
b) 10 10
c) Undefined behaviour
d) 10 11
Answer: a
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10;
  5.         int *p = &i;
  6.         foo(&p);
  7.         printf("%d ", *p);
  8.         printf("%d ", *p);
  9.     }
  10.     void foo(int **const p)
  11.     {
  12.         int j = 11;
  13.         *p = &j;
  14.         printf("%d ", **p);
  15.     }

a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash
Answer: b
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10;
  5.         int *const p = &i;
  6.         foo(&p);
  7.         printf("%dn", *p);
  8.     }
  9.     void foo(int **p)
  10.     {
  11.         int j = 11;
  12.         *p = &j;
  13.         printf("%dn", **p);
  14.     }

a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash
Answer: a
Clarification: None.

9. Which of the following is the correct syntax to send an array as a parameter to function?
a) func(&array);
b) func(#array);
c) func(*array);
d) func(array[size]);
Answer: a
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *