Function Prototypes and Parameters(pass by value, pass by reference) MCQs in C Language
1.
What is the output?
#include <stdio.h>
void fun(int a) {
a = a + 5;
printf("%d", a);
}
int main() {
int x = 10;
fun(x);
printf("%d", x);
}
A) 15 10
B) 10 15
C) 15 15
D) 10 10
✅ Answer: A
Explanation:x is passed by value → a inside function is a copy → modified → prints 15. Original x remains 10 → prints 10.
2.
Which of the following is a correct function prototype?
A) int add(int,int);
B) add int(int,int);
C) void int add(int,int);
D) int() add;
✅ Answer: A
Explanation:
Function prototype syntax → return_type function_name(parameter_types);.
3.
Output:
#include <stdio.h>
void swap(int *a,int *b) {
int t = *a; *a = *b; *b = t;
}
int main() {
int x = 2, y = 3;
swap(&x,&y);
printf("%d %d", x, y);
}
A) 2 3
B) 3 2
C) 5 5
D) Compiler error
✅ Answer: B
Explanation:
Passing pointers → function modifies original variables → swapped → prints 3 2.
4.
Which statement is TRUE for pass by value?
A) Function can modify original variable
B) Function receives a copy → original unchanged
C) Requires pointers
D) Always faster
✅ Answer: B
Explanation:
Call by value passes a copy → original variable remains unaffected.
5.
Output:
#include <stdio.h>
void increment(int *p) {
(*p)++;
}
int main() {
int x = 5;
increment(&x);
printf("%d", x);
}
A) 5
B) 6
C) Compiler error
D) 0
✅ Answer: B
Explanation:
Passing pointer → increments original → prints 6.
6.
Output:
#include <stdio.h>
void fun(int a, int b) {
a = a + 1; b = b + 1;
}
int main() {
int x = 2, y = 3;
fun(x,y);
printf("%d %d", x,y);
}
A) 3 4
B) 2 3
C) 3 3
D) 2 4
✅ Answer: B
Explanation:
Call by value → function modifies copies → original x,y unchanged → prints 2 3.
7.
Which is correct function prototype?
A) void swap(int a,int b);
B) void swap(int *a,int *b);
C) Both A & B
D) void swap(a,b);
✅ Answer: C
Explanation:
Both are valid prototypes depending on pass by value or pass by reference via pointers.
8.
Output:
#include <stdio.h>
void display(int n) {
printf("%d", n);
}
int main() {
int x = 5;
display(x+3);
}
A) 5
B) 8
C) 53
D) Compiler error
✅ Answer: B
Explanation:x+3 = 8 → passed by value → prints 8.
9.
Which of the following cannot be passed by reference?
A) Variable
B) Array
C) Pointer
D) Literal value
✅ Answer: D
Explanation:
C cannot pass literals by reference → only variables or arrays.
10.
Output:
#include <stdio.h>
void add(int *a, int *b) {
*a = *a + *b;
}
int main() {
int x = 2, y = 3;
add(&x,&y);
printf("%d", x);
}
A) 2
B) 3
C) 5
D) Compiler error
✅ Answer: C
Explanation:
Passing pointers → modifies original → x=2+3=5 → prints 5.
11.
Output:
#include <stdio.h>
void increment(int a) {
a++;
}
int main() {
int x = 10;
increment(x);
printf("%d", x);
}
A) 10
B) 11
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → function modifies copy → original x remains 10.
12.
Which of the following statements is TRUE about pass by reference?
A) Uses pointers
B) Original variable modified
C) Function can return void
D) All of the above
✅ Answer: D
Explanation:
All statements are correct for pass by reference in C.
13.
Output:
#include <stdio.h>
void swap(int a,int b) {
int t=a; a=b; b=t;
}
int main() {
int x=2,y=3;
swap(x,y);
printf("%d %d", x,y);
}
A) 3 2
B) 2 3
C) 5 5
D) Compiler error
✅ Answer: B
Explanation:
Call by value → only copies swapped → original unchanged → prints 2 3.
14.
Which is correct function pointer declaration?
A) int (*ptr)(int,int);
B) int ptr(*int,int);
C) (*int) ptr(int,int);
D) int *ptr(int,int);
✅ Answer: A
Explanation:
ptr points to a function taking (int,int) and returning int.
15.
Output:
#include <stdio.h>
void fun(int *a) {
(*a) += 10;
}
int main() {
int x=5;
fun(&x);
printf("%d", x);
}
A) 5
B) 10
C) 15
D) Compiler error
✅ Answer: C
Explanation:
Pointer allows modification → x = 5+10 = 15.
16.
Output:
#include <stdio.h>
int sum(int a,int b) {
return a+b;
}
int main() {
int (*ptr)(int,int)=sum;
printf("%d", ptr(2,3));
}
A) Compiler error
B) 23
C) 5
D) 6
✅ Answer: C
Explanation:
Function pointer calls sum(2,3) → returns 5 → printed.
17.
Output:
#include <stdio.h>
void add(int *a,int *b) {
*a = *a + *b;
}
int main() {
int x=2, y=3;
add(&x,&y);
printf("%d", x);
}
A) 2
B) 3
C) 5
D) Compiler error
✅ Answer: C
Explanation:
Passing pointers → modifies x → prints 5.
18.
Which is incorrect call for void fun(int,int);?
A) fun(2,3);
B) fun(1,1);
C) fun(5);
D) fun(0,0);
✅ Answer: C
Explanation:
Function expects 2 parameters → passing 1 → compiler error.
19.
Output:
#include <stdio.h>
void increment(int *p) {
*p = *p + 1;
}
int main() {
int a=7;
increment(&a);
printf("%d", a);
}
A) 7
B) 8
C) 0
D) Compiler error
✅ Answer: B
Explanation:
Pointer modifies original → 7+1=8 → printed.
20.
Output:
#include <stdio.h>
void fun(int x) {
x = x*2;
}
int main() {
int a=5;
fun(a);
printf("%d", a);
}
A) 5
B) 10
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → a unchanged → prints 5.
21.
Output:
#include <stdio.h>
void fun(int arr[]) {
arr[0] = 100;
}
int main() {
int a[3] = {1,2,3};
fun(a);
printf("%d", a[0]);
}
A) 1
B) 100
C) 0
D) Compiler error
✅ Answer: B
Explanation:
Arrays decay to pointers → arr[0] modifies original array → prints 100.
22.
Output:
#include <stdio.h>
void fun(int *x) {
*x += 10;
}
int main() {
int a=5;
fun(&a);
printf("%d", a);
}
A) 5
B) 10
C) 15
D) Compiler error
✅ Answer: C
Explanation:
Pointer allows modification → a = 5+10 = 15 → printed.
23.
Which of the following is correct call by reference?
A) fun(a); where void fun(int *p)
B) fun(&a); where void fun(int *p)
C) fun(*a); where void fun(int *p)
D) fun(a*2); where void fun(int *p)
✅ Answer: B
Explanation:
Function expects pointer → pass address of variable using &a.
24.
Output:
#include <stdio.h>
void swap(int *a,int *b) {
int t=*a; *a=*b; *b=t;
}
int main() {
int x=3,y=7;
swap(&x,&y);
printf("%d %d", x,y);
}
A) 3 7
B) 7 3
C) 10 10
D) Compiler error
✅ Answer: B
Explanation:
Pass by reference via pointer → original variables swapped → 7 3.
25.
Output:
#include <stdio.h>
void fun(int x) {
x = x*2;
}
int main() {
int a=4;
fun(a);
printf("%d", a);
}
A) 4
B) 8
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → original variable a unchanged → prints 4.
26.
Output:
#include <stdio.h>
void add(int *a,int *b) {
*a += *b;
*b = *a - *b;
}
int main() {
int x=2,y=3;
add(&x,&y);
printf("%d %d", x,y);
}
A) 5 2
B) 2 3
C) 5 3
D) 5 5
✅ Answer: A
Explanation:
x=2+3=5, y=5-3=2 → prints 5 2.
27.
Which is true about passing arrays to functions?
A) Arrays always passed by value
B) Arrays always passed by reference (decay to pointer)
C) Arrays cannot be passed
D) Arrays are copied internally
✅ Answer: B
Explanation:
Arrays decay to pointers → function can modify original array elements.
28.
Output:
#include <stdio.h>
void fun(int a[]) {
a[1] = a[1] + 5;
}
int main() {
int arr[3] = {1,2,3};
fun(arr);
printf("%d", arr[1]);
}
A) 2
B) 7
C) 5
D) Compiler error
✅ Answer: B
Explanation:
arr decays to pointer → arr[1] modified → prints 7.
29.
Output:
#include <stdio.h>
void increment(int *p) {
(*p)++;
}
int main() {
int x=10;
increment(&x);
increment(&x);
printf("%d", x);
}
A) 10
B) 11
C) 12
D) 13
✅ Answer: C
Explanation:
Two increments → 10+1+1=12 → printed.
30.
Which is TRUE about function prototypes in C?
A) Parameter names are mandatory
B) Parameter types are mandatory
C) Function must be defined immediately
D) Return type can be omitted
✅ Answer: B
Explanation:
Parameter types are mandatory in prototype; names optional.
31.
Output:
#include <stdio.h>
void fun(int a,int b) {
a += b;
b += a;
}
int main() {
int x=1,y=2;
fun(x,y);
printf("%d %d", x,y);
}
A) 1 2
B) 3 5
C) 3 3
D) 1 5
✅ Answer: A
Explanation:
Call by value → modifications inside fun() do not affect original variables.
32.
Output:
#include <stdio.h>
void modify(int *p) {
*p *= 2;
}
int main() {
int a=7;
modify(&a);
printf("%d", a);
}
A) 7
B) 14
C) 0
D) Compiler error
✅ Answer: B
Explanation:
Pointer modifies original variable → 7*2=14 → printed.
33.
Which statement is TRUE?
A) Passing literal to a function requiring pointer is valid
B) Function prototype allows only return type
C) Pass by value cannot modify original variable
D) Function cannot return pointer
✅ Answer: C
Explanation:
Call by value → function modifies copy only → original variable unaffected.
34.
Output:
#include <stdio.h>
void swap(int *a,int *b) {
int t=*a; *a=*b; *b=t;
}
int main() {
int x=5,y=10;
swap(&x,&y);
printf("%d %d", x,y);
}
A) 5 10
B) 10 5
C) 15 5
D) 5 15
✅ Answer: B
Explanation:
Pass by reference swaps original values → prints 10 5.
35.
Output:
#include <stdio.h>
void fun(int n) {
if(n==0) return;
printf("%d", n);
fun(n-1);
}
int main() {
fun(3);
}
A) 123
B) 321
C) 3
D) Compiler error
✅ Answer: B
Explanation:
Recursion prints n down → 3 2 1 → B.
36.
Output:
#include <stdio.h>
void fun(int *a,int *b) {
*a = *a + *b;
}
int main() {
int x=2,y=3;
fun(&x,&y);
printf("%d", x);
}
A) 2
B) 3
C) 5
D) Compiler error
✅ Answer: C
Explanation:
x modified via pointer → prints 5.
37.
Output:
#include <stdio.h>
void increment(int a[]) {
a[0]++;
}
int main() {
int arr[2]={1,2};
increment(arr);
printf("%d", arr[0]);
}
A) 1
B) 2
C) 3
D) Compiler error
✅ Answer: B
Explanation:
Array passed by reference → arr[0]=1+1=2 → printed.
38.
Which is FALSE about pass by reference using pointers?
A) Function can modify original variable
B) Can pass array
C) Can pass pointer
D) Can pass literal value
✅ Answer: D
Explanation:
Cannot pass literal → no address to reference.
39.
Output:
#include <stdio.h>
void fun(int *p) {
*p += 5;
}
int main() {
int a=10;
fun(&a);
printf("%d", a);
}
A) 10
B) 5
C) 15
D) Compiler error
✅ Answer: C
Explanation:
Pointer modifies original variable → 10+5=15 → printed.
40.
Output:
#include <stdio.h>
void fun(int a) {
a += 10;
}
int main() {
int x=5;
fun(x);
printf("%d", x);
}
A) 5
B) 15
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → original x unchanged → prints 5.
41.
Output:
#include <stdio.h>
void fun(int *p) {
*p += 2;
}
int main() {
int a=3;
fun(&a);
fun(&a);
printf("%d", a);
}
A) 3
B) 4
C) 5
D) 7
✅ Answer: D
Explanation:
Two increments via pointer → 3+2=5, 5+2=7 → printed 7.
42.
Which is correct function prototype for a function returning a pointer to int?
A) int* fun(int a);
B) int fun*(int a);
C) *int fun(int a);
D) int fun(int a*);
✅ Answer: A
Explanation:
Correct syntax → return type int*, function name fun, parameter int a.
43.
Output:
#include <stdio.h>
void fun(int a[]) {
a[0] = a[0] + 5;
}
int main() {
int arr[2]={2,3};
fun(arr);
printf("%d", arr[0]);
}
A) 2
B) 5
C) 7
D) Compiler error
✅ Answer: C
Explanation:
Array passed by reference → arr[0] modified → 2+5=7.
44.
Output:
#include <stdio.h>
void add(int *a,int *b) {
*a = *a + *b;
*b = *a - *b;
}
int main() {
int x=3,y=4;
add(&x,&y);
printf("%d %d", x,y);
}
A) 3 4
B) 7 3
C) 7 4
D) Compiler error
✅ Answer: B
Explanation:
x = x+y = 7, y = 7-4 =3 → prints 7 3.
45.
Which is TRUE for pass by value?
A) Function can modify original variable
B) Function cannot modify original variable
C) Always faster than pass by reference
D) Cannot pass arrays
✅ Answer: B
Explanation:
Function receives a copy → original variable remains unchanged.
46.
Output:
#include <stdio.h>
void fun(int *a,int b) {
*a = *a + b;
}
int main() {
int x=2,y=3;
fun(&x,y);
printf("%d", x);
}
A) 2
B) 3
C) 5
D) Compiler error
✅ Answer: C
Explanation:
Pointer allows modification of x → x = 2+3=5.
47.
Which is correct function declaration?
A) int sum(int,int);
B) int sum(a,b); int a,b;
C) int sum(int a,int b) { return a+b; }
D) All of the above
✅ Answer: D
Explanation:
All are valid C declarations/definitions.
48.
Output:
#include <stdio.h>
void fun(int *a,int *b) {
int t=*a; *a=*b; *b=t;
}
int main() {
int x=5,y=8;
fun(&x,&y);
printf("%d %d", x,y);
}
A) 5 8
B) 8 5
C) 13 8
D) 5 13
✅ Answer: B
Explanation:
Pointers allow swapping → prints 8 5.
49.
Output:
#include <stdio.h>
void increment(int arr[], int n) {
for(int i=0;i<n;i++) arr[i]++;
}
int main() {
int a[3]={1,2,3};
increment(a,3);
printf("%d", a[2]);
}
A) 3
B) 4
C) 5
D) Compiler error
✅ Answer: B
Explanation:
arr[2]=3 → incremented by 1 → 4 → printed.
50.
Which is FALSE about pass by reference using pointers?
A) Original variable can be modified
B) Arrays can be passed
C) Pointers can be passed
D) Literal values can be passed
✅ Answer: D
Explanation:
Cannot pass literal → no memory address.
51.
Output:
#include <stdio.h>
void fun(int *p) {
(*p) += 5;
}
int main() {
int a=7;
fun(&a);
fun(&a);
printf("%d", a);
}
A) 7
B) 12
C) 17
D) Compiler error
✅ Answer: C
Explanation:
Two increments: 7+5=12, 12+5=17 → printed 17.
52.
Output:
#include <stdio.h>
void fun(int x) {
x = x*2;
}
int main() {
int a=4;
fun(a);
printf("%d", a);
}
A) 4
B) 8
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → original variable unchanged → prints 4.
53.
Which is TRUE about array parameter in C?
A) Arrays are passed by value
B) Arrays decay to pointers → pass by reference
C) Array elements cannot be modified inside function
D) Function cannot accept array
✅ Answer: B
Explanation:
Arrays decay to pointers → modifications inside function affect original array.
54.
Output:
#include <stdio.h>
void add(int *a,int *b) {
*a = *a + *b;
*b = *a - *b;
}
int main() {
int x=3,y=5;
add(&x,&y);
printf("%d %d", x,y);
}
A) 3 5
B) 8 3
C) 8 5
D) Compiler error
✅ Answer: B
Explanation:
x=3+5=8, y=8-5=3 → prints 8 3.
55.
Output:
#include <stdio.h>
void fun(int a) {
a++;
}
int main() {
int x=10;
fun(x);
printf("%d", x);
}
A) 10
B) 11
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → original x unchanged → prints 10.
56.
Which is correct function pointer syntax?
A) void (*fp)(int);
B) int (*fp)();
C) char (*fp)(char);
D) All of the above
✅ Answer: D
Explanation:
All are correct function pointer declarations.
57.
Output:
#include <stdio.h>
void fun(int *p) {
*p = *p*2;
}
int main() {
int x=5;
fun(&x);
printf("%d", x);
}
A) 5
B) 10
C) 0
D) Compiler error
✅ Answer: B
Explanation:
Pointer modifies x → x=5*2=10 → printed.
58.
Which is TRUE for function prototype?
A) Must specify return type
B) Parameter types mandatory
C) Parameter names optional
D) All of the above
✅ Answer: D
Explanation:
All statements are correct.
59.
Output:
#include <stdio.h>
void fun(int arr[2]) {
arr[1] += 5;
}
int main() {
int a[2]={1,2};
fun(a);
printf("%d", a[1]);
}
A) 2
B) 5
C) 7
D) Compiler error
✅ Answer: C
Explanation:
Array passed by reference → arr[1]=2+5=7 → printed.
60.
Output:
#include <stdio.h>
void swap(int *x,int *y) {
int t=*x; *x=*y; *y=t;
}
int main() {
int a=3,b=6;
swap(&a,&b);
printf("%d %d", a,b);
}
A) 3 6
B) 6 3
C) 9 6
D) 3 9
✅ Answer: B
Explanation:
Pointers swap values → prints 6 3.
61.
Output:
#include <stdio.h>
void multiply(int *a,int b) {
*a = *a * b;
}
int main() {
int x=3;
multiply(&x,4);
printf("%d", x);
}
A) 3
B) 4
C) 12
D) Compiler error
✅ Answer: C
Explanation:
Pointer modifies original variable → 3*4=12 → printed.
62.
Which is correct function prototype for a function taking an array of integers?
A) void fun(int arr[]);
B) void fun(int *arr);
C) Both A & B
D) void fun(int arr);
✅ Answer: C
Explanation:
Array decays to pointer → both are valid prototypes.
63.
Output:
#include <stdio.h>
void fun(int *p) {
(*p)++;
}
int main() {
int a=7;
fun(&a);
fun(&a);
printf("%d", a);
}
A) 7
B) 8
C) 9
D) 10
✅ Answer: C
Explanation:
Two increments: 7+1+1=9 → printed.
64.
Which is FALSE about function pointers?
A) Can store address of a function
B) Can call a function indirectly
C) Can point to variables
D) Can be passed as arguments
✅ Answer: C
Explanation:
Function pointers point to functions, not variables.
65.
Output:
#include <stdio.h>
void swap(int *a,int *b) {
int t=*a; *a=*b; *b=t;
}
int main() {
int x=8,y=5;
swap(&x,&y);
printf("%d %d", x,y);
}
A) 8 5
B) 5 8
C) 13 5
D) 8 13
✅ Answer: B
Explanation:
Pointers swap original values → prints 5 8.
66.
Output:
#include <stdio.h>
void fun(int *arr,int n) {
for(int i=0;i<n;i++) arr[i] += 2;
}
int main() {
int a[3]={1,2,3};
fun(a,3);
printf("%d", a[2]);
}
A) 3
B) 4
C) 5
D) Compiler error
✅ Answer: C
Explanation:
a[2]=3 → incremented by 2 → 5 → printed.
67.
Which is TRUE about pass by reference using pointers?
A) Function can modify original variable
B) Can pass array or pointer
C) Literal cannot be passed
D) All of the above
✅ Answer: D
Explanation:
All statements are correct.
68.
Output:
#include <stdio.h>
void increment(int *x,int *y) {
(*x)++; (*y)++;
}
int main() {
int a=1,b=2;
increment(&a,&b);
printf("%d %d", a,b);
}
A) 1 2
B) 2 3
C) 1 3
D) 2 2
✅ Answer: B
Explanation:
Pointers modify original variables → a=2, b=3 → printed.
69.
Output:
#include <stdio.h>
void fun(int x) {
x *= 2;
}
int main() {
int a=5;
fun(a);
printf("%d", a);
}
A) 5
B) 10
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → original variable unchanged → prints 5.
70.
Output:
#include <stdio.h>
int sum(int *arr,int n) {
int s=0;
for(int i=0;i<n;i++) s += arr[i];
return s;
}
int main() {
int a[3]={1,2,3};
printf("%d", sum(a,3));
}
A) 3
B) 6
C) 1
D) Compiler error
✅ Answer: B
Explanation:
Sum = 1+2+3 = 6 → printed.
71.
Output:
#include <stdio.h>
void fun(int *x) {
*x += 5;
}
int main() {
int a=10;
fun(&a);
printf("%d", a);
}
A) 10
B) 5
C) 15
D) Compiler error
✅ Answer: C
Explanation:
Pointer modifies original → 10+5=15 → printed.
72.
Which is FALSE about function prototype in C?
A) Return type must be specified
B) Parameter types mandatory
C) Parameter names are mandatory
D) Function must be defined after prototype
✅ Answer: C
Explanation:
Parameter names are optional in prototype.
73.
Output:
#include <stdio.h>
void swap(int *a,int *b) {
int t=*a; *a=*b; *b=t;
}
int main() {
int x=4,y=9;
swap(&x,&y);
printf("%d %d", x,y);
}
A) 4 9
B) 9 4
C) 13 9
D) 4 13
✅ Answer: B
Explanation:
Pointers swap original → prints 9 4.
74.
Output:
#include <stdio.h>
void modify(int arr[]) {
arr[0] = arr[0]*2;
}
int main() {
int a[2]={3,5};
modify(a);
printf("%d", a[0]);
}
A) 3
B) 6
C) 5
D) Compiler error
✅ Answer: B
Explanation:
Array passed by reference → a[0]=3*2=6 → printed.
75.
Which is TRUE about arrays as function parameters?
A) Passed by value
B) Passed by reference (decay to pointer)
C) Cannot be modified in function
D) Cannot be passed
✅ Answer: B
Explanation:
Arrays decay to pointer → modifications inside function affect original array.
76.
Output:
#include <stdio.h>
void fun(int *p,int n) {
for(int i=0;i<n;i++) p[i]+=1;
}
int main() {
int a[3]={1,2,3};
fun(a,3);
printf("%d", a[1]);
}
A) 2
B) 3
C) 4
D) Compiler error
✅ Answer: B
Explanation:
a[1]=2 → incremented by 1 → 3 → printed.
77.
Output:
#include <stdio.h>
void fun(int *x,int *y) {
*x = *x + *y;
}
int main() {
int a=2,b=3;
fun(&a,&b);
printf("%d", a);
}
A) 2
B) 3
C) 5
D) Compiler error
✅ Answer: C
Explanation:
a modified via pointer → 2+3=5 → printed.
78.
Which is TRUE about passing struct to function by reference?
A) Use pointer to struct
B) Can modify original struct
C) Saves memory for large structs
D) All of the above
✅ Answer: D
Explanation:
All statements correct → pointer allows pass by reference.
79.
Output:
#include <stdio.h>
void fun(int *x) {
*x *= 2;
}
int main() {
int a=6;
fun(&a);
printf("%d", a);
}
A) 6
B) 12
C) 0
D) Compiler error
✅ Answer: B
Explanation:
Pointer modifies a → 6*2=12 → printed.
80.
Output:
#include <stdio.h>
void fun(int x) {
x += 10;
}
int main() {
int a=5;
fun(a);
printf("%d", a);
}
A) 5
B) 15
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → original variable unchanged → prints 5.
81.
Output:
#include <stdio.h>
void fun(int *p) {
(*p)++;
}
int main() {
int x=1;
fun(&x);
fun(&x);
fun(&x);
printf("%d", x);
}
A) 1
B) 2
C) 3
D) 4
✅ Answer: D
Explanation:
Three increments via pointer: 1+1+1+1=4 → printed.
82.
Output:
#include <stdio.h>
void fun(int *x,int *y) {
*x = *x + *y;
}
int main() {
int a=3,b=5;
fun(&a,&b);
printf("%d %d", a,b);
}
A) 3 5
B) 8 5
C) 8 3
D) Compiler error
✅ Answer: B
Explanation:
a modified via pointer → 3+5=8, b unchanged → prints 8 5.
83.
Output:
#include <stdio.h>
void fun(int *arr,int n) {
for(int i=0;i<n;i++) arr[i] *= 2;
}
int main() {
int a[3]={1,2,3};
fun(a,3);
printf("%d", a[2]);
}
A) 3
B) 6
C) 4
D) Compiler error
✅ Answer: B
Explanation:
a[2]=3 → multiplied by 2 → 6 → printed.
84.
Which is FALSE about pass by value?
A) Original variable remains unchanged
B) Function receives a copy
C) Can modify original variable
D) Faster than pass by reference (usually)
✅ Answer: C
Explanation:
Call by value cannot modify original variable.
85.
Output:
#include <stdio.h>
void fun(int *p) {
*p = *p*3;
}
int main() {
int x=2;
fun(&x);
printf("%d", x);
}
A) 2
B) 6
C) 0
D) Compiler error
✅ Answer: B
Explanation:
Pointer multiplies original → 2*3=6 → printed.
86.
Output:
#include <stdio.h>
void fun(int x[]) {
x[0] += 10;
}
int main() {
int a[2]={5,7};
fun(a);
printf("%d", a[0]);
}
A) 5
B) 7
C) 15
D) Compiler error
✅ Answer: C
Explanation:
Array decays to pointer → a[0]=5+10=15 → printed.
87.
Output:
#include <stdio.h>
void modify(int *a,int *b) {
int temp=*a;
*a=*b; *b=temp;
}
int main() {
int x=4,y=9;
modify(&x,&y);
printf("%d %d", x,y);
}
A) 4 9
B) 9 4
C) 13 9
D) 4 13
✅ Answer: B
Explanation:
Pointers swap values → prints 9 4.
88.
Output:
#include <stdio.h>
void increment(int x) {
x += 10;
}
int main() {
int a=7;
increment(a);
printf("%d", a);
}
A) 7
B) 17
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → original variable unchanged → prints 7.
89.
Output:
#include <stdio.h>
void sum(int *arr,int n,int *res) {
*res=0;
for(int i=0;i<n;i++) *res += arr[i];
}
int main() {
int a[3]={1,2,3}, s;
sum(a,3,&s);
printf("%d", s);
}
A) 3
B) 6
C) 1
D) Compiler error
✅ Answer: B
Explanation:
Sum of array =1+2+3=6 → printed.
90.
Output:
#include <stdio.h>
void fun(int *x,int n) {
for(int i=0;i<n;i++) (*x)++;
}
int main() {
int a=3;
fun(&a,4);
printf("%d", a);
}
A) 3
B) 4
C) 7
D) 8
✅ Answer: D
Explanation:
4 increments via pointer → 3+4=7 → wait, let’s recalc carefully.
- Initial a=3
- fun increments *x 4 times: 3→4→5→6→7 ✅ Correct
So correct printed value is 7, not 8.
✅ Answer: C
Explanation:
Pointer increments 4 times → 3+4=7 → printed.
91.
Output:
#include <stdio.h>
void fun(int *p) {
*p += 10;
}
int main() {
int a=5;
fun(&a);
fun(&a);
printf("%d", a);
}
A) 5
B) 10
C) 25
D) 15
✅ Answer: D
Explanation:
Two increments: 5+10=15, 15+10=25 ✅ Wait recalc
- First fun: 5+10=15
- Second fun: 15+10=25 ✅ Correct
✅ Answer: C
Explanation:
Pointer modifies original variable twice → 25 → printed.
92.
Which is TRUE about static local variables with function calls?
A) Value persists across calls
B) Resets on every call
C) Cannot be used with pointers
D) Only global variables persist
✅ Answer: A
Explanation:
Static local variable retains value between function calls.
93.
Output:
#include <stdio.h>
void fun(int *x,int *y) {
*x = *x + *y;
*y = *x - *y;
}
int main() {
int a=2,b=3;
fun(&a,&b);
printf("%d %d", a,b);
}
A) 2 3
B) 5 2
C) 5 3
D) Compiler error
✅ Answer: B
Explanation:
a=2+3=5, b=5-3=2 → prints 5 2.
94.
Output:
#include <stdio.h>
void increment(int *p) {
(*p)++;
}
int main() {
int x=0;
increment(&x);
increment(&x);
increment(&x);
printf("%d", x);
}
A) 0
B) 1
C) 2
D) 3
✅ Answer: D
Explanation:
Three increments via pointer → 0+1+1+1=3 → printed.
95.
Output:
#include <stdio.h>
void fun(int a,int *b) {
a = a+2; *b = *b+2;
}
int main() {
int x=2,y=3;
fun(x,&y);
printf("%d %d", x,y);
}
A) 2 3
B) 4 5
C) 4 3
D) 2 5
✅ Answer: D
Explanation:
x passed by value → unchanged, y passed by reference → y=3+2=5 → prints 2 5.
96.
Output:
#include <stdio.h>
void swap(int *a,int *b) {
int t=*a; *a=*b; *b=t;
}
int main() {
int x=1,y=2;
swap(&x,&y);
printf("%d %d", x,y);
}
A) 1 2
B) 2 1
C) 3 2
D) 1 3
✅ Answer: B
Explanation:
Pointers swap values → prints 2 1.
97.
Output:
#include <stdio.h>
void doubleValue(int *x) {
*x *= 2;
}
int main() {
int a=5;
doubleValue(&a);
printf("%d", a);
}
A) 5
B) 10
C) 0
D) Compiler error
✅ Answer: B
Explanation:
Pointer multiplies a → 5*2=10 → printed.
98.
Output:
#include <stdio.h>
void fun(int a[]) {
a[1] += 3;
}
int main() {
int arr[2]={2,5};
fun(arr);
printf("%d", arr[1]);
}
A) 2
B) 5
C) 8
D) Compiler error
✅ Answer: C
Explanation:
Array passed by reference → arr[1]=5+3=8 → printed.
99.
Output:
#include <stdio.h>
void fun(int *a,int *b) {
*a = *a+*b;
*b = *a-*b;
}
int main() {
int x=1,y=2;
fun(&x,&y);
printf("%d %d", x,y);
}
A) 1 2
B) 3 1
C) 3 2
D) Compiler error
✅ Answer: B
Explanation:
x=1+2=3, y=3-2=1 → prints 3 1.
100.
Output:
#include <stdio.h>
void fun(int a) {
a++;
}
int main() {
int x=7;
fun(x);
printf("%d", x);
}
A) 7
B) 8
C) Compiler error
D) 0
✅ Answer: A
Explanation:
Call by value → original variable unchanged → prints 7.