• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Pointer Basics

Question 21

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) C
char *pChar;
int *pInt;
float *pFloat;

sizeof(pChar);
sizeof(pInt);
sizeof(pFloat);
What’s the size returned for each of sizeof() operator?
  • 4 4 4
  • 1 4 4
  • 1 4 8
  • None of the above

Question 22

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 valid address. C
int* ptr1, ptr2;
  • TRUE
  • FALSE

Question 23

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 24

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 25

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 26

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 27

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 28

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

Question 29

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

  • Depends on compiler
     

  • (*ptrdata)++
     

  • *(ptrdata)++
     

  • *(ptrdata++)
     

Question 30

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 :
  • p, q, r, s
  • q, r, s, p
  • r, s, q, p
  • r, s, p, q

There are 43 questions to complete.

Last Updated :
Take a part in the ongoing discussion