pointers_mcqs_word
pointers_mcqs_word
1) How do you declare a pointer to a function that takes two integers and returns an integer in
C?
a) int(*ptr)(int,int);
b) ptr(int,int) int;
c) function int (*ptr)(int,int);
d) ptr function(int,int) int;
a) 30
b) value of x
c) address of x
d) Error
a) 10
b) 6
c) 30
d) Error
6) If X, Y and Z are pointer variables of type char, int and float, respectively in ‘C’ language, then
which of the following statements is true?
a) Size of X, Y and Z are same
b) Size of Z is greater than the size of X
c) Size of Y is greater than the size of X
d) Size of Z is greater than the size of Y
a) 555
b) 5 5 junk
c) 5 junk junk
d) Compile time error
8) What is the output of this C program?
#include<stdio.h>
void square (int *x)
{
*x = (*x)++ *(*x);
}
void square(int *x, int *y)
{
*x = (*x) * --(*y);
}
int main()
{
int number = 30;
square(&number, &number);
printf(“%d”, number);
return 0;
}
a) 910
b) 920
c) 870
d) 900
a) Pointer to a pointer
b) Pointer to an array of chars
c) Pointer to function taking char* argument and returns an int
d) Throws an error
10) What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
a) ((((a+i)+j)+k)+l)
b) *(*(*(*(a+i)+j)+k)+l)
c) (((a+i)+j)+k+l)
d) ((a+i)+j+k+l)
int main()
{
int x = 5, y = 10;
swap(&x, &y);
printf("x = %d, y = %d", x, y);
return 0;
}
a) 2
b) 4
c) 6
d) 8
a) 2
b) 3
c) 4
d) Undefined behavior
14) What will be the output of the following code?
#include <stdio.h>
void func(int *p)
{
*p = 20;
p = NULL;
}
int main()
{
int x = 10;
int *ptr = &x;
func(ptr);
printf("%d", x);
return 0;
}
a) 10
b) 20
c) 0
d) Undefined behavior
a) ho
b) he
c) h l
d) Undefined behavior
a) 1
b) 2
c) 3
d) Error