Pointer in C MCQs Exercise I


Ques 1 Pointer


What will be output of following C code ?
#include<stdio.h>
int main( )
{
    int arr[]={10,20};
    int *p=arr;
    ++*p;
    printf("%d %d %d",arr[0],arr[1],*p);
    return 0;
}

  a) 11 20 11
  b) 78 33 12
  c) 13 45 12
  d) 23 66 11


a is the correct option





Ques 2 Pointer


What will be output of following C code ?
#include<stdio.h>
int main( )
{
    int arr[]={10,20};
    int *p=arr;
    *p++;
    printf("%d %d %d",arr[0],arr[1],*p);
    return 0;
}

  a) 11 20 11
  b) 11 20 20
  c) 12 45 12
  d) 23 66 11


b is the correct option





Ques 3 Pointer


What will be output of following C code ?
#include<stdio.h>
int main( )
{
    int k=20;
    void *p==&k;
    printf("%d",*p);
    return 0;
}

  a) 20
  b) Address of k
  c) Compiler Error
  d) None of these


c is the correct option





Ques 4 Pointer


What will be output of following C code ?

void f(int *p,int *q)
{
    p=q;
    *p=2;
}
int i=0,j=0;
int main( )
{
    f(&i,&j);
    printf("%d %d\n",i,j);
    return 0;
}

  a) 2 2
  b) 2 1
  c) 0 1
  d) 0 2


d is the correct option