Select chapter



functions (3.papers)
loops (1.papers)
arrays (2.papers)
structures (3.papers)
unions (1.papers)
pointers (7.papers)
null pointers (1.papers)
strings (2.papers)
misc c concepts (1.papers)
Data structures (5.papers)
linked lists (3.papers)
trees (1.papers)
basics (5.papers)
Hide

Sponsored Links


  

c pointers interview questions and answers

1
address of array vs address of array[0]:

What is the output of below C program?

#include  <stdio.h>

int main(void)
{
    int arr[5] = {1,2,3,4,5};
    printf("%p\n",arr);
    printf("%p\n",&arr);
    printf("%p\n",&arr[0]);
    return 0;
}
  1. all prints same, base address of array.
  2. first and third prints same value, second prints different address.
  3. first and second prints same address and third prints different address.
  4. second and third prints same address and first prints different address.
Show Answer
Share Facebook gmail Twitter
2
Difference between pointer and address of a pointer:

What is the output of below C program?

#include  <stdio.h>

int main(void)
{
    int *p = malloc(sizeof(int) * 5);
    
    printf("%p\n",p);
    printf("%p\n",&p);
    printf("%p\n",&p[0]);
    return 0;
}
  1. all prints same, base address of array.
  2. first and third prints same value, second prints different address.
  3. first and second prints same address and third prints different address.
  4. second and third prints same address and first prints different address.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
5
Is it possible to assign a pointer of char, to array (of char)?
  1. Yes, because both holds characters only internally.
  2. Array base address can't be modified (it is unmodifiable lvalue).
  3. yes, but result is unpredictable, it may crash at run time.
  4. none
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
7
what is p in below code?

char ch[6] = "skill";
char (*p)[6] = &ch;
  1. p is an array of 6 char pointers.
  2. p is a pointer to an  array of 6 chars.
  3. invalid declaration, gives compile time error.
  4. p is pointer to a function which takes array as parameter and returns a char.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
9
what is arr in below code?

int *arr;
arr = malloc(sizeof(int) * 5); 
  1. it is an array of 5 integers.
  2. arr is a pointer which is holding the address of starting location of 5 ints which was allocated sequentially.
  3. arr is a pointer which is holding the address of starting location of 5 ints which was allocated randomly.
  4. it gives compile time error.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
11
what is step 3 doing in below example?

1. int **arr = malloc(3 * sizeof(int *)); 
    
2. for(int i=0; i<3; i++)
3.     arr[i] = malloc(2 * sizeof(int)); 
  1. we have created a double pointer to int, first we are allocating 3 pointers to it, where each pointer is pointing to an array of 2 ints.
  2. we have created a double pointer to int, first we are allocating 3bytes to it, where each byte is pointing to an array of 2 ints.
  3. it gives compile time error.
  4. it will crash.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
15
If a two dimensional array is passed to a function where 2-d array is having 3 rows & 4 columns, then how to write the formal parameters of the function definition which takes these parameters?
  1. #include  <stdio.h>
    void fun(int arr[][4]);
    int main(void)
    {
        int arr[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
        fun(arr);
        return 0;
    }
    void fun(int arr[][4])
    {
        printf("function..");
    }
  2. #include  <stdio.h>
    void fun(int (*arr)[4]);
    int main(void)
    {
        int arr[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
        fun(arr);
        return 0;
    }
    void fun(int (*arr)[4])
    {
        printf("function..");
    }
Show Answer
Share Facebook gmail Twitter
16
what is arr in below code, and what are we allocating to it?

int **arr = malloc(3 * sizeof(int *)); 
  1. arr is pointer to pointer to int. we are allocating array of 3 pointers to it.
  2. arr is a void pointer to an int pointer. we are allocating 12 bytes to it.
  3. it gives compile time error.
  4. it will crash.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
Is it possible to increment array base address, in c?
  1. Yes.
  2. No, as it is unmodifiable l value.
  3. yes, but result is unpredictable, it may crash at run time.
  4. none
Show Answer
Share Facebook gmail Twitter
Read more papers :