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
char *a; 
what is this declaration?
  1. a is character to a pointer
  2. a is pointer to a character
  3. a is a pointer to a character pointer
  4. none of the above
Show Answer
Share Facebook gmail Twitter
2
What is a pointer?
  1. it is a variable, which holds the address of something of that data type.
  2. pointer can hold addresses and values also.
  3. option1 is true, and it can hold the address of functions also.
  4. option 2 is true, and it can hold address of a function also.
Show Answer
Share Facebook gmail Twitter
3
Is it possible to get the address of a function, in c?
  1. no
  2. some times it is possible and some times not
  3. Yes, using function pointers.
  4. Yes using void pointers.
Show Answer
Share Facebook gmail Twitter
4
public void fun(int *); 
Is it a function declaration or definition?
  1. declaration
  2. definition
  3. both declaration and definition.
  4. there is nothing like function declaration
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
7
Sample code for using pointers in c:
What will be the output of this below program?

#include  <stdio.h>
int fun(void);

main()
{
    int i = 10;
    int *p = &i;
    printf("%d\n",i); //a
    printf("%p\n",&i);//b
    printf("%d\n",*p);//c
    printf("%p\n",&p);//d
    printf("%p\n",p);//e
    printf("%d\n",*(&i));//f
}
  1. a-10, b-address of i, c-10, d-address of i, e-address of i, f-address of i
  2. a-10, b-address of i, c-10, d-address of p, e-address of i, f-10
  3. a-10, b-address of i, c-address of p, d-address of i, e-address of i, f-10.
  4. none
Show Answer
Share Facebook gmail Twitter
8
What is the difference between int *i; float *f; ?
  1. both are pointers only, no difference.
  2. i is a pointer to an integer pointer; f is a pointer to a floating pointer.
  3. i contains address of an integer, f contains address of a float value.
  4. i is an integer, f is a float.
Show Answer
Share Facebook gmail Twitter
9
Example code for using void pointer in c:

what is the mistake in this c code?

main()
{
int *i = malloc(10);
void *p = i;
}
  1. No error.
  2. we have to typecast malloc to (int *) else it gives error.
  3. we can't assign integer pointer to void pointer.
  4. we can assign integer pointer to void pointer, but we have to typecast it while assigning, else it gives compile time error.
Show Answer
Share Facebook gmail Twitter
10
Demo code for using malloc and void pointer in c:

what is the mistake in this c code?

#include  <stdio.h>

main()
{
    int *i = malloc(sizeof(int));
    *i=100;
    printf("%d",*i);
    
    void *p = i;
    printf("%d",*p);
}
  1. No error.
  2. we can't reference void pointer. second printf is wrong.
  3. we can't reference int pointer, first printf is wrong.
  4. no error but no output.
Show Answer
Share Facebook gmail Twitter
11
char **a; 
what is this declaration?
  1. a is character to a pointer
  2. a is pointer to a character
  3. a is a pointer to a character pointer
  4. a is a character pointer to a void pointer.
Show Answer
Share Facebook gmail Twitter
12
Where does malloc allocate memory?
  1. data segment
  2. heap
  3. stack
  4. code segment
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
14
Example for passing pointers to function in c:
What does below function do?

void strfun(char *dst, const char *src)
{
while(*dst++=*src++);
}
  1. It is copying the contents of src string to dst string.
  2. it is an example of infinite loop. Each time when it is entering while loop, it is comparing for equality of the characters of both the pointers, which will never end.
  3. it copies the first character of src to first character of dst.
  4. while loop can't have a semicolon. it gives compile time error.
Show Answer
Share Facebook gmail Twitter
15
What is below code trying to do? what will be the output?

int num = 1;
if(*(char *)&num == 1)
{
printf("LE ");
}
else 
{
printf("BE");
}
  1. This program will find out what kind of machine you are using , little endian or big endian. If it is little endian, prints LE. else BE.
  2. This program will find out what kind of machine you are using , little endian or big endian. If it is little endian, prints BE. else LE.
  3. This program will crash as we are typecasting int pointer to char pointer and then comparing it with 1.
  4. This program will find out what kind of machine you are using , little endian or big endian. But since logic to find it is wrong, it prints BE all the times.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
18
What is the difference between malloc() and calloc() functions in c?
  1. malloc - allocates memory, and zero initializes the buffer. calloc - allocates memory, and doesn't zero initializes the buffer
  2. malloc - allocates memory, and doesn't zero initializes the buffer. calloc - allocates memory, and zero initializes the buffer
  3. Option 1 is right, and malloc is easy to use when we are allocating memory for multiple blocks.
  4. Option 2 is right, and calloc is easy to use when we are allocating memory for multiple blocks.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
Which of the below commands properly allocates memory?
  1. char a*=new char(20);
  2. char a=new char(20);
  3. char a=new char[20];
  4. depends on the compiler
Show Answer
Share Facebook gmail Twitter
Read more papers :