0% found this document useful (0 votes)
3 views

pointers_mcqs_word

The document contains a series of multiple-choice questions related to pointers in C programming. It covers topics such as function pointers, pointer arithmetic, and pointer behavior in various scenarios. Each question provides options for answers, testing knowledge of C pointer concepts.

Uploaded by

lalitha vaddadi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

pointers_mcqs_word

The document contains a series of multiple-choice questions related to pointers in C programming. It covers topics such as function pointers, pointer arithmetic, and pointer behavior in various scenarios. Each question provides options for answers, testing knowledge of C pointer concepts.

Uploaded by

lalitha vaddadi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Pointers

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;

2) The output of the following program is:


#include<stdio.h>
int main(void)
{
int x, *p;
x = 30;
p = x;
printf(“%d”, *p);
return 0;
}

a) 30
b) value of x
c) address of x
d) Error

3) Consider the following C code segment:


int a = 10, b = 20;
int *p = &a, *q = &b;
p = q;
With respect to the code segment mentioned above, which of the following statements is
correct?

a) Both a and b will contain 20


b) Both p and q will point to b
c) Both p and q will point to a
d) Error

4) Consider the following C program:


#include<stdio.h>
int main()
{
int a[ ] = {2,4,6,8,10};
int i, sum = 0, *b = a + 4;
for (i = 0; i < 5; i++)
sum = sum + (*b – i) - *(b – i);
printf(“ %d \n”, sum);
return 0;
}

The output of the above C program is:

a) 10
b) 6
c) 30
d) Error

5) Consider the following C function


#include< stdio.h>
int main()
{
char c[ ] = “ICRBCSIT17”;
char *p = c;
printf(“%s” , c + 2[p] – 6[p] -1);
return 0;
}

The output of the program is


a) SI
b) IT
c) 17
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

7) What is the output of this C Code?


#include<stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf(“ %d %d %d\n”, k, *p, **m);
}

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

9) What does the following statement mean?


int (*fp)(char*)

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)

11) #include <stdio.h>


void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}

int main()
{
int x = 5, y = 10;
swap(&x, &y);
printf("x = %d, y = %d", x, y);
return 0;
}

a) Swaps the values of x and y


b) Prints x = 5, y = 10
c) Prints x = 10, y = 5
d) Results in a compilation error

12) #include <stdio.h>


int main()
{
int arr[] = {2, 4, 6, 8};
int *p = arr + 3;
printf("%d", *(--p));
return 0;
}

a) 2
b) 4
c) 6
d) 8

13) #include <stdio.h>


int main()
{
int arr[] = {1, 2, 3, 4, 5};
int *p = arr + 2;
int *q = arr;
printf("%d", p - q);
return 0;
}

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

15) #include <stdio.h>


int main()
{
char *str = "hello";
printf("%c %c", *str, *(str + 4));
return 0;
}

a) ho
b) he
c) h l
d) Undefined behavior

16) Is the NULL pointer same as an uninitialized pointer?


a) True
b) False

17) What does the following declaration mean?


int (*ptr)[10];

a) ptr is an array of pointers to 10 integers


b) ptr is a pointer to an array of 10 integers
c) ptr is an array of 10 integers
d) ptr is a pointer to array
18) What is the output of the following program
int arr[5] = {1,2,3,4,5};
int *ptr = arr;
printf(“%d”, *(ptr++));

a) 1
b) 2
c) 3
d) Error

You might also like