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

https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on_14.html
1. What is the output of this C code?
#include
void foo(int*);
int main()
{
int i = 10;
foo((&i)++);
}
void foo(int *p)
{
printf("%d\n", *p);
}
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
Answer: c
2. What is the output of this C code?
#include
void foo(int*);
int main()
{
int i = 10, *p = &i;
foo(p++);
}
void foo(int *p)
{
printf("%d\n", *p);
}
a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault
b) Some garbage value
c) Compile time error
d) Segmentation fault
Answer: a
.
.
3. What is the output of this C code?
#include
void foo(float *);
int main()
{
int i = 10, *p = &i;
foo(&i);
}
void foo(float *p)
{
printf("%f\n", *p);
}
a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
b) 0.000000
c) Compile time error
d) Undefined behaviour
Answer: b
4. What is the output of this C code?
#include
int main()
{
int i = 97, *p = &i;
foo(&i);
printf("%d ", *p);
}
void foo(int *p)
{
int j = 2;
p = &j;
printf("%d ", *p);
}
a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash
b) 2 2
c) Compile time error
d) Segmentation fault/code crash
Answer: a
5. What is the output of this C code?
#include
int main()
{
int i = 97, *p = &i;
foo(&p);
printf("%d ", *p);
return 0;
}
void foo(int **p)
{
int j = 2;
*p = &j;
printf("%d ", **p);
}
a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash
Answer: a
6. What is the output of this C code?
#include
int main()
{
int i = 11;
int *p = &i;
foo(&p);
printf("%d ", *p);
}
void foo(int *const *p)
{
int j = 10;
*p = &j;
printf("%d ", **p);
}
a) Compile time error
b) 10 10
c) Undefined behaviour
d) 10 11
b) 10 10
c) Undefined behaviour
d) 10 11
Answer: a
7. What is the output of this C code?
#include
int main()
{
int i = 10;
int *p = &i;
foo(&p);
printf("%d ", *p);
printf("%d ", *p);
}
void foo(int **const p)
{
int j = 11;
*p = &j;
printf("%d ", **p);
}
a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash
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?
#include
int main()
{
int i = 10;
int *const p = &i;
foo(&p);
printf("%d\n", *p);
}
void foo(int **p)
{
int j = 11;
*p = &j;
printf("%d\n", **p);
}
a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash
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?
#include
void m(int *p, int *q)
{
int temp = *p; *p = *q; *q = temp;
}
void main()
{
int a = 6, b = 5;
m(&a, &b);
printf("%d %d\n", a, b);
}
a) 5 6
b) 6 5
c) 5 5
d) 6 6
b) 6 5
c) 5 5
d) 6 6
Answer: a
15. What is the output of this C code?
#include
void m(int *p)
{
int i = 0;
for(i = 0;i < 5; i++)
printf("%d\t", p[i]);
}
void main()
{
int a[5] = {6, 5, 3};
m(&a);
}
a) 0 0 0 0 0
b) 6 5 3 0 0
c) Run time error
d) 6 5 3 junk junk
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?
#include
void m(int p, int q)
{
int temp = p;
p = q;
q = temp;
}
void main()
{
int a = 6, b = 5;
m(a, b);
printf("%d %d\n", a, b);
}
a) 5 6
b) 5 5
c) 6 5
d) 6 6
b) 5 5
c) 6 5
d) 6 6
Answer: c
17. What is the output of this C code?
#include
void m(int p, int q)
{
printf("%d %d\n", p, q);
}
void main()
{
int a = 6, b = 5;
m(a);
}
a) 6
b) 6 5
c) 6 junk value
d) Compile time error
b) 6 5
c) 6 junk value
d) Compile time error
Answer: d
18. What is the output of this C code?
#include
void m(int p)
{
printf("%d\n", p);
}
void main()
{
int a = 6, b = 5;
m(a, b);
printf("%d %d\n", a, b);
}
a) 6
b) 6 5
c) 6 junk value
d) Compile time error
b) 6 5
c) 6 junk value
d) Compile time error
Answer: d