MCQ on Pointers in C/C++(Pointers Multiple choice questions)

MCQ on Pointers in C/C++ with answers and explanations for placement tests and job interviews. These solved C Pointers MCQ are useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our Pointer MCQ ( pointer multiple Choice Questions ) focuses on all areas of the pointers and their concept. We will regularly update the quiz and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

We have already published a blog post that contains short questions on pointers. If you want you can also see this blog post “Pointer interview questions in C/C++“.

Guideline of Pointers MCQ:

This MCQ on Pointers is intended for checking your Pointers knowledge. It takes 1hours 15 minutes to pass the Pointer MCQ. If you don’t finish the MCQ on Pointers within the mentioned time, all the unanswered questions will count as wrong. You can miss the questions by clicking the “Next” button and return to the previous questions by the “Previous” button. Every unanswered question will count as wrong. MCQ on Pointers has features of randomization which feel you a new question set at every attempt.

In this MCQ on Pointers, we have also implemented a feature that not allowed the user to see the next question or finish the quiz without attempting the current pointer MCQ.

5 votes, 5 avg

You have 1 hours 15 minutes to take the Pointer MCQs

Your time has been Over.


Pointers MCQ

C Programming Multiple Choice Questions And Answers

Pointers MCQ: Pointers Multiple Choice Questions and Answers

1 / 56

Which is an indirection operator among the following?

2 / 56

What is the output of the below code?

#include<stdio.h>

void fun(int **p)
{
  static int q = 40;
  *p = &q;
}

int main()
{
  int data = 27;

  int *ptr = &data;

  fun(&ptr);

  printf("%d", *ptr);

  return 0;
}

 

3 / 56

Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of x and y.

int main()
{
    int array[] = {3, 5, 1, 4, 6, 2};
    int done = 0;
    int i;

    while (done == 0)
    {
        done  = 1;
        for (i = 0; i <= 4; i++)
        {
            if (array[i] < array[i+1])
            {
                swap(&array[i], &array[i+1]);
                done = 0;
            }
        }
        for (i = 5; i >= 1; i--)
        {
            if (array[i] > array[i-1])
            {
                swap(&array[i], &array[i-1]);
                done = 0;
            }
        }
    }

    printf("%d", array[3]);
}

GATE-CS-2017 (Set 2)

The output of the program is _____.

4 / 56

What are the different ways to initialize an array with all elements as zero?

5 / 56

What is the output of the below code?

#include<stdio.h>

int main()
{
    int *ptr;
    
    *ptr = 5;
    
    printf("%d", *ptr);
    
    return 0;
}

 

6 / 56

What does the following expression mean? 

//pointer Quiz

char ∗(∗(∗ a[T]) ( )) ( );

 

7 / 56

What is the output of the below code?

#include<stdio.h>

int main()
{
    int i = 3;
    int *j;
    int **k;
    j = &i;
    k = &j;
    k++;
    printf("%d ",**k);
    return 0;
}

 

8 / 56

What is the output of the below code?

#include <stdio.h>

int main()
{
    int data = 24;
    int *ptr = NULL;
    int **ptr1 = NULL;
    ptr = &data;
    ptr1 = &ptr;
    printf("%d\n", *ptr );
    printf("%d\n", **ptr1);

    return 0;
}

 

9 / 56

What is the output of the below code?

#include<stdio.h>

int main()
{
    printf("%u",sizeof(NULL));
    
    return 0;
}

 

10 / 56

What is the output of the below code?

#include <stdio.h>

int main()
{
    char *pcData="aticleworld";
    printf("%c ",6[pcData]);

    return 0;
}

 

11 / 56

What does the following C-statement declare?

//Declaration

int ( * f) (int * ) ;

 

12 / 56

Faster access to non-local variables is achieved using an array of pointers to activation records, called a

13 / 56

What is the output of the below code?

#include "stdio.h"

typedef void (*fPtr)(int);

void display(int a)
{
    printf("%d\n",a);
}

int main()
{
    fPtr fPtr1 = NULL, fPtr2 = NULL;

    fPtr1 = &display;

    fPtr2 = display;

    (*fPtr1)(10);

    fPtr2(10);

    return 0;
}

 

14 / 56

What is the output of the below program?

#include<stdio.h>

int main()
{
    int * ptr = NULL;
    
    printf("%d",*ptr);
    
    return 0;
}

 

15 / 56

What is the output?

#include<stdio.h>

void fun(int *p, int *q)
{
    p = q;
    *p = 2;
}

int main()
{
    int i = 0, j = 1;

    fun(&i, &j);

    printf("%d %d", i, j);

    return 0;
}

 

16 / 56

What does the following ‘C’ statement declare?

//Syntax

int * f [ ] ( );

 

17 / 56

Which of the following is true with respect to Reference?

18 / 56

What is the output of the below code?

#include <stdio.h>

int f(int x, int *py, int **ppz)
{
    int y, z;
    **ppz += 1;
    z  = **ppz;
    *py += 2;
    y = *py;
    x += 3;
    return x + y + z;
}

void main()
{
    int c, *b, **a;
    c = 4;
    b = &c;
    a = &b;
    printf( "%d", f(c,b,a));
    return 0;
}

 

19 / 56

Can we combine the two statements?

char *ptr;

ptr = (char*) malloc(100);

 

20 / 56

What is the output of the below code?

#include <stdio.h>

int main(void)
{
    int aiData[5] = {100,200,30,40,50};
    
    int *piData = aiData;
    
    *++piData;
    
    printf("aiData[0] = %d, aiData[1] = %d, *piData = %d", aiData[0], aiData[1], *piData);
    
    return 0;
}

 

21 / 56

What is the output of the below code?

#include<stdio.h>

void fun(int **p)
{
  int q = 40;
  *p = &q;
}

int main()
{
  int data = 27;

  int *ptr = &data;

  fun(&ptr);

  printf("%d", *ptr);

  return 0;
}

 

22 / 56

What is the output of the below code?

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void fun(char** ptr)
{
    ptr++;
}
int main()
{
    char *str = malloc(20*sizeof(char));
    if(str == NULL)
        return -1;

    strcpy(str, "Aticleworld");

    fun(&str);

    puts(str);

    free(str);

    return 0;
}

 

23 / 56

Consider the following C code

int main()
{
    int a = 300;
    
    char *b = (char *)&a;
    
    *++b = 2;
    
    printf("%d ",a);
    
    return 0;
}

Consider the size of int is two bytes and the size of char as one byte. Predict the output of the following code. Assume that the machine is little-endian.

24 / 56

A function q that accepts a pointer to a character as an argument and returns a pointer to an array of 5 integers can be declared as

25 / 56

Assume int is 4 bytes, char is 1 byte and float is 4 bytes. Also, assume that pointer size is 4 bytes (i.e. typical case)

char *pChar;
int *pInt;
float *pFloat;

sizeof(pChar);
sizeof(pInt);
sizeof(pFloat);

What’s the size returned for each of the sizeof() operator?

26 / 56

Is there any issue with the below program?

#include "stdlib.h"

int main()
{
    int *ptr1;
    int **ptr2;
    int **ptr3;
    
    ptr1 = (int*)malloc(sizeof(int));
    ptr2 = (int**)malloc(10*sizeof(int*));
    ptr3 = (int**)malloc(10*sizeof(int*));
    
    free(ptr1);
    free(ptr2);
    free(*ptr3);
    
    return 0;
}

 

27 / 56

calloc(m, n); is equivalent to

28 / 56

What is the output of the below code?

#include <stdio.h>

int main(void)
{
    int * piData;
    {
        //block
        int Data = 27;
        piData = &Data;
    }
    printf("piData = %d\n", *piData);

    return 0;
}

 

29 / 56

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?

30 / 56

Assume that an int variable takes 4 bytes and a char variable takes 1 byte

#include<stdio.h>

int main()
{
    int arr[] = {10, 20, 30, 40, 50, 60};

    int *ptr1 = arr;
    int *ptr2 = arr + 5;

    printf("%d\n",(ptr2 - ptr1));

    printf("%d\n",(char*)ptr2 - (char*) ptr1);

    return 0;
}

 

31 / 56

Consider the following table

A.  Activation record p. Linking loader
B.  Location counter q. Garbage collection
C. Reference counts r. Subroutine call
D.  Address relocation s. Assembler

Matching A, B, C, D in the same order gives :

32 / 56

‘ptr’ is a pointer to a data type. The expression *ptr++ is evaluated as (in C++) :

33 / 56

The reason for using pointers in a C program is

34 / 56

What is the output of the following program?

#include <stdio.h>

void fun(int x)
{
    x = 30;
}

int main()
{
    int y = 20;

    fun(y);

    printf("%d", y);

    return 0;
}

 

35 / 56

What is the output of the below code?

#include<stdio.h>
int main()
{
    register int data = 10;
    int *ptr = NULL;
    ptr = &data;
    printf("%d ",*ptr);
    return 0;
}

 

36 / 56

What is the output of the below code?

#include<stdio.h>

void fun(int *p)
{
  int q = 40;
  p = &q;
}

int main()
{
  int data = 27;

  int *ptr = &data;

  fun(ptr);

  printf("%d", *ptr);

  return 0;
}

 

37 / 56

What is the output of the below program?

#include<stdio.h>

int main()
{
    char *ptr = "Aticleworld.com";

    printf("%c\n", *&*&*ptr);

    return 0;
}

 

38 / 56

What is the output of the below code?

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i;
    int *ptr = (int *) malloc(5 * sizeof(int));
    if(ptr == NULL)
    {
        return -1;
    }
    for (i=0; i<5; i++)
    {
        *(ptr + i) = i;
    }
    printf("%d ", *ptr++);
    printf("%d ", (*ptr)++);
    printf("%d ", *ptr);
    printf("%d ", *++ptr);
    printf("%d ", ++*ptr);

    return 0;
}

 

39 / 56

What will be the output produced by the following C code?

int main()
{
    int array[5][5];

    printf("%d",( (array == *array) && (*array == array[0]) ));

    return 0;
}

 

40 / 56

Suppose that in a C program snippet, the following statements are used.

i) sizeof(int);

ii) sizeof(int*);

iii) sizeof(int**);

Assuming the size of the pointer is 4 bytes and the size of the int is also 4 bytes, pick the most correct answer from the given options.

41 / 56

Consider this C code to swap two integers and these five statements after it:

void swap(int *px, int *py)
{
*px = *px - *py;
*py = *px + *py;
*px = *py - *px;
}

P1: will generate a compilation error P2: may generate a segmentation fault at runtime depending on the arguments passed P3: correctly implements the swap procedure for all input pointers referring to integers stored in memory locations accessible to the process P4: implements the swap procedure correctly for some but not all valid input pointers P5: may add or subtract integers and pointers.

42 / 56

What is the output of the below program? Assume the sizeof an integer and a pointer is 4 bytes.

#include <stdio.h>

int main()
{
    int (*ptr)[5][10];

    printf("%d",  sizeof(*ptr));

    return 0;
}

 

43 / 56

What is the output of the below code?

int main()
{
    int aiData[5] = {100,200,300,400,500};
    
    int *piData = aiData;
    
    ++*piData;
    
    printf("aiData[0] = %d, aiData[1] = %d, *piData = %d", aiData[0], aiData[1], *piData);
    
    return 0;
}

 

44 / 56

What is the output of the above program?

#include<stdio.h>

int main()
{
    int a;
    char *x;

    x = (char *) &a;

    a = 512;

    x[0] = 1;

    x[1] = 2;

    printf("%d\n",a);

    return 0;
}

 

45 / 56

The following statement in ‘C’ declares?

int (*f())[ ];

 

46 / 56

Prior to using a pointer variable, it should be

47 / 56

What is the output of the below program? The assumed size of char, int, and double is 1,4,8.

#include<stdio.h>

int main()
{
    int a, b, c;
    char *p = 0;
    int *q = 0;
    double *r = 0;
    
    a = (int)(p + 1);
    b = (int)(q + 1);
    c = (int)(r + 1);
    
    printf("%d %d  %d",a, b, c);
    
    return 0;
}

 

48 / 56

What is the output of the below code?

#include 

int main()
{
    void *ptr;

    ptr = (void*)0;

    printf("%u",sizeof(ptr));

    return 0;
}

 

49 / 56

What is the output of the below program?

#include<stdio.h>

void fun(int arr[])
{
    int i;
    for (i = 0; i < (sizeof(arr)/sizeof(arr[0])); ++i)
    {
        printf("%d ", arr[i]);
    }
}

int main()
{
    int arr[4] = {10, 20,30, 40};

    fun(arr);

    return 0;
}

 

50 / 56

Consider the following declaration:

int a, *b=&a, **c=&b;

The following program fragment

a=4;

**c=5;

 

51 / 56

The output of the following program?

#include <stdio.h>

int main()
{
    int *ptr;
    int x;

    ptr = &x;
    *ptr = 0;

    printf(" x = %d\n", x);
    printf(" *ptr = %d\n", *ptr);

    *ptr += 5;
    printf(" x  = %d\n", x);
    printf(" *ptr = %d\n", *ptr);

    (*ptr)++;
    printf(" x = %d\n", x);
    printf(" *ptr = %d\n", *ptr);

    return 0;
}

 

52 / 56

Below declaration means,

//Declaration

int (*p) [5];

 

53 / 56

What is the output of the below code?

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

void fun(char** ptr)
{
    (*ptr)++;
}

int main()
{
    char *str = malloc(20*sizeof(char));
    if(str == NULL)
        return -1;
        
    strcpy(str, "Aticleworld");
    
    fun(&str);
    puts(str);
    free(str);
    
    return 0;
}

 

54 / 56

In the below statement, ptr1 and ptr2 are uninitialized pointers to int i.e. they are pointing to some random address that may or may not be a valid address.

//Declaration

int* ptr1, ptr2;

 

55 / 56

What is the output of the below code?

#include<stdio.h>

int main()
{
    int data = 27;
    int *ptr = &data;
    
    printf("%u %u", *&ptr, &*ptr);
    
    return 0;
}

 

56 / 56

Consider a compiler where int takes 4 bytes, char takes 1 byte and pointer takes 4 bytes.

#include <stdio.h>

int main()
{
    int arr1[] = {1, 2,3};
    int *ptr1 = arr1;

    char arr2[] = {1, 2,3};
    char *ptr2 = arr2;

    printf("sizeof arr1[] = %d ", sizeof(arr1));

    printf("sizeof ptr1 = %d ", sizeof(ptr1));

    printf("sizeof arr2[] = %d ", sizeof(arr2));

    printf("sizeof ptr2 = %d ", sizeof(ptr2));

    return 0;
}

 

 

Your score is

The average score is 0%

0%

Recommended Articles for you:

3 comments

  1. Hi,

    #include
    int main()
    {
    char* pcData = “aticleworld”;
    printf(“%c”,6[pcData]);
    return 0;
    }

    Output: w

    but ans is showing in this MCQ is a

Leave a Reply

Your email address will not be published. Required fields are marked *