C Pointer Basics

Last Updated :
Discuss
Comments

Question 1

Consider the following declaration:

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

The following program fragment

a=4;
**c=5;
  • A

    does not change the value of a

  • B

    assigns address of c to a

  • C

    assigns the value of b to a

  • D

    assigns 5 to a

Question 2

Consider the following C program. 

C
#include<stdio.h>
void mystery(int *ptra, int *ptrb) 
{
   int *temp;
   temp = ptrb;
   ptrb = ptra;
   ptra = temp;
}
int main() 
{
    int a=2016, b=0, c=4, d=42;
    mystery(&a, &b);
    if (a < c)
       mystery(&c, &a);
    mystery(&a, &d);
    printf("%d", a);
}

The output of the program _____________   Note : This question was asked as Numerical Answer Type.

  • A

    2016

  • B

    0

  • C

    4

  • D

    8

Question 3

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;    
}
  • A
    1
  • B
    0
  • C
    2
  • D
    -1

Question 4

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 as two bytes and size of char as one byte. Predict the output of the following code . Assume that the machine is little-endian.
  • A
    556
  • B
    300
  • C
    Runtime Error
  • D
    Compile Time Error

Question 5

Consider the following function implemented in C:

void printxy(int x, int y)
{
    int *ptr;
    x = 0;
    ptr = &x;
    y = *ptr;
    *ptr = 1;
    printf("%d,%d", x, y);
}

The output of the printxy(1,1) is

  • A

    0,0

  • B

    0,1

  • C

    1,0

  • D

    1,1

Question 6

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]);
}

The output of the program is _____. Note: This question appeared as Numerical Answer Type.

  • A

    1

  • B

    2

  • C

    3

  • D

    4

Question 7

Faster access to non-local variables is achieved using an array of pointers to activation records, called a
  • A
    stack
  • B
    heap
  • C
    display
  • D
    activation tree

Question 8

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

  • A

    Depends on compiler
     

  • B

    (*ptrdata)++
     

  • C

    *(ptrdata)++
     

  • D

    *(ptrdata++)
     

Question 9

Consider the following table

A. Activation recordp. Linking loader
B. Location counterq. Garbage collection
C. Reference countsr. Subroutine call
D. Address relocations. Assembler

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

  • A

    p, q, r, s

  • B

    q, r, s, p

  • C

    r, s, q, p

  • D

    r, s, p, q

Question 10

What does the following C-statement declare? int (*f) (int*);

  • A

    A function that takes an integer pointer as argument and returns an integer

  • B

    A function that takes an integer as argument and returns an integer pointer

  • C

    A pointer to a function that takes an integer pointer as argument and returns an integer

  • D

    A function that takes an integer pointer as argument and returns a function pointer

Tags:

There are 47 questions to complete.

Take a part in the ongoing discussion