Loading...

C Multiple Choice Questions

Our C questions and answers focuses on all areas of C programming language covering 100+ topics in C

C Pointers-1 MCQs

C Pointers-1


1. A pointer is a

a) variable that stores address of an instruction
b) variable that stores address of other variable
c) keyword used to create variables
d) None of these



2. The reason for using pointers in a Cprogram is

a) Pointers allow different functions to share and modify their local variables
b) To pass large structures so that complete copy of the structure can be avoided
c) Pointers enable complex “linked" data structures like linked lists and binary trees
d) All of the above



3. How can you write a[i][j][k][l] in equivalent pointer expression?

a) (((***(a+i)+j)+k)+l)
b) ((**(*(a+i)+j)+k)+l)
c) (*(*(*(a+i)+j)+k)+l)
d) *(*(*(*(a+i)+j)+k)+l)



4. What is the output of this C code?
int main() {
  int i = 10;
  void *p = &i;
  printf("%d\n" (int)*p);
  return 0;
}

a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviour



5. Comment on the following pointer declaration?
int *ptr, p;

a) ptr is a pointer to integer, p is not
b) ptr and p, both are pointers to integer
c) ptr is pointer to integer, p may or may not be
d) ptr and p both are not pointers to integer



6. What will be the output of the following C code?
void main() {
  char *p;
  p = "Hello";
  printf("%c\n", *&*p);
}

a) Hello
b) H
c) Some address will be printed
d) None of these



7. The address operator &, cannot act on

a) R-values
b) Arithmetic expressions
c) Both of the above
d) Local variables



8. Check whether the condition is correct or not?
int **a;

a) is illegal
b) is legal but meaningless
c) is syntactically and semantically correct
d) None of these



9. What will be the output of the following program?
void main() {
  int i = 10;
  void *p = &i;
  printf("%d\n", (int)*p;
}

a) Compiler time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behavior



10. What will be the output of the program if the array begins at 1000 and each integer occupies 2 bytes?
void main() {
  int i = 10;
  void *p = &i;
  printf("%f\n", *(float *)p);
}

a) Error
b) 10
c) 0.0000000
d) None of these



- Related Topics