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;
  • does not change the value of a

  • assigns address of c to a

  • assigns the value of b to a

  • 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.

  • 2016

  • 0

  • 4

  • 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;    
}
  • 1
  • 0
  • 2
  • -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.
  • 556
  • 300
  • Runtime Error
  • 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

  • 0,0

  • 0,1

  • 1,0

  • 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.

  • 1

  • 2

  • 3

  • 4

Question 7

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

Question 8

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

  • Depends on compiler
     

  • (*ptrdata)++
     

  • *(ptrdata)++
     

  • *(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 :

  • p, q, r, s

  • q, r, s, p

  • r, s, q, p

  • r, s, p, q

Question 10

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

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

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

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

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

Tags:

There are 43 questions to complete.

Take a part in the ongoing discussion