C Programming Questions and Answers – Pointers and Function Arguments
C Programming Questions and Answers – Pointers and Function Arguments
1.What is the output of this C code?
#include <stdio.h>
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
View Answer
2.What is the output of this C code?
#include <stdio.h>
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
View Answer
3.What is the output of this C code?
#include <stdio.h>
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
View Answer
4.What is the output of this C code?
#include <stdio.h>
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
View Answer
5.What is the output of this C code?
#include <stdio.h>
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
View Answer
6.What is the output of this C code?
#include <stdio.h>
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
View Answer
7.What is the output of this C code?
#include <stdio.h>
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
View Answer
8.What is the output of the code below?
#include <stdio.h>
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
View Answer
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]);
View Answer
10.Which of the following can never be sent by call-by-value?
a) Variable
b) Array
c) Structures
d) Both (b) and (c)
View Answer
11.Which type of variables can have same name in different function:
a) global variables
b) static variables
c) Function arguments
d) Both (b) and (c)
View Answer
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
View Answer
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
View Answer
14.What is the output of this C code?
#include <stdio.h>
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
View Answer
15.What is the output of this C code?
#include <stdio.h>
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
View Answer
16.What is the output of this C code?
#include <stdio.h>
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
View Answer
17.What is the output of this C code?
#include <stdio.h>
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
View Answer
18.What is the output of this C code?
#include <stdio.h>
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