C Programming Questions and Answers on Pointers and Function Arguments for Freshers

1. What is the output of this 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("%d\n", *p);
  11.     }
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
Answer: c
2. What is the output of this 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("%d\n", *p);
  11.     }
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault
Answer: a
.
3. What is the output of this 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("%f\n", *p);
  11.     }
a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
Answer: b
4. What is the output of this 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
5. What is the output of this 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
6. What is the output of this 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
7. What is the output of this 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
8. What is the output of the code below?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10;
  5.         int *const p = &i;
  6.         foo(&p);
  7.         printf("%d\n", *p);
  8.     }
  9.     void foo(int **p)
  10.     {
  11.         int j = 11;
  12.         *p = &j;
  13.         printf("%d\n", **p);
  14.     }
a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash
Answer: a
9. Which of the following are correct syntaxes to send an array as a parameter to function:

a) func(&array);
b) func(#array);
c) func(*array);
d) func(array[size]);
Answer: a
10. Which of the following can never be sent by call-by-value?

a) Variable
b) Array
c) Structures
d) Both Array and Structures
Answer: b
11. Which type of variables can have same name in different function:

a) global variables
b) static variables
c) Function arguments
d) Both static variables and Function arguments
Answer: d
12. Arguments that take input by user before running a program are called?

a) main function arguments
b) main arguments
c) Command-Line arguments
d) Parameterized arguments
Answer: c
13. The maximum number of arguments that can be passed in a single function are_____________

a) 127
b) 253
c) 361
d) No limits in number of arguments
Answer: b
14. What is the output of this C code?
  1.     #include 
  2.     void m(int *p, int *q)
  3.     {
  4.         int temp = *p; *p = *q; *q = temp;
  5.     }
  6.     void main()
  7.     {
  8.         int a = 6, b = 5;
  9.         m(&a, &b);
  10.         printf("%d %d\n", a, b);
  11.     }
a) 5 6
b) 6 5
c) 5 5
d) 6 6
Answer: a
15. What is the output of this C code?
  1.     #include 
  2.     void m(int *p)
  3.     {
  4.         int i = 0;
  5.         for(i = 0;i < 5; i++)
  6.         printf("%d\t", p[i]);
  7.     }
  8.     void main()
  9.     {
  10.         int a[5] = {6, 5, 3};
  11.         m(&a);
  12.     }
a) 0 0 0 0 0
b) 6 5 3 0 0
c) Run time error
d) 6 5 3 junk junk
Answer: b
16. What is the output of this C code?
  1.     #include 
  2.     void m(int p, int q)
  3.     {
  4.         int temp = p;
  5.         p = q;
  6.         q = temp;
  7.     }
  8.     void main()
  9.     {
  10.         int a = 6, b = 5;
  11.         m(a, b);
  12.         printf("%d %d\n", a, b);
  13.     }
a) 5 6
b) 5 5
c) 6 5
d) 6 6
Answer: c
17. What is the output of this C code?
  1.     #include 
  2.     void m(int p, int q)
  3.     {
  4.         printf("%d %d\n", p, q);
  5.     }
  6.     void main()
  7.     {
  8.         int a = 6, b = 5;
  9.         m(a);
  10.     }
a) 6
b) 6 5
c) 6 junk value
d) Compile time error
Answer: d
18. What is the output of this C code?

  1.     #include 
  2.     void m(int p)
  3.     {
  4.         printf("%d\n", p);
  5.     }
  6.     void main()
  7.     {
  8.         int a = 6, b = 5;
  9.         m(a, b);
  10.         printf("%d %d\n", a, b);
  11.     }
a) 6
b) 6 5
c) 6 junk value
d) Compile time error
Answer: d

Related

Multiple Choice Questions 3444258083859463545

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item