Pointers Questions and Answers

Practice Mode
Showing 10 of 217 questions
Q81
char ptrl [ ] = "Drama Actor "; char *ptr2 = malloc ( 5 ); ptr2 = ptrl; What is wrong with the above code (assuming the call to malloc does not fail )?
  • A There will bea memory overwrite.
  • B It will not compile.
  • C There will be a segmentation fault.
  • D Not enough space is allocated by the malloc.
Answer: Option A
Q82
char echo [ 50 ] = "Brain Power"; char *ptr = echo + 5; From the sample above, which would be the proper way to copy 20 bytes from the location pointted to by ptr to the beginning of echo ?
  • A memcpy (echo, ptr, 20);
  • B It cannot be done, because the source and destination overlap.
  • C strncpy (echo, ptr, 20);
  • D memmove (echo, ptr, 20);
Answer: Option D
Q83
char sub1 [ 100] = "tamil"; char sub2 [100] = "Hindi"; char *strptrl = sub1 + 2; char *strptr2=sub2 + 3; strcpy (strptrl, sub2 ); strcpy ( strptr2, sub1 ); printf ("%s\n", sub1 ); printf ( "%s\n", sub2 ); Given the sample code above, which of the following string values will be printed when the code is executed ?
  • A Ta Hin Tamil Hin Tamil
  • B Tam Hindi HiTamHindi
  • C TaHindi HinTahindi
  • D TaHindi HintTamil
Answer: Option D
Q84
Scrutinize the following code in C. char fruit [ ]  = "Orange"; char *ptr: ptr = fruit; What will be the output for the following expression ? printf ("%c", * (ptr + 2 ));
  • A r
  • B a
  • C n
  • D none
Answer: Option B
Q85
In the given code: int a[50]; int *ptr; ptr = a; To access the 7th element of the array which of the following is incorrect ?
  • A *(a+6)
  • B a[6]
  • C ptr[6]
  • D *(*ptr+6)
Answer: Option D
Q86
main ( ) { int a [5] = {-2, -1, 3, 4, 5}; int *b; b = &a [ 2]; Then the value of b[-1] is;
  • A 4
  • B 3
  • C -1
  • D -2
Answer: Option C
Q87
main () { int a = 5, *ptr; ptr = &a; printf ("%d", ++*ptr); } The output might be:
  • A 6
  • B 5
  • C 0
  • D none
Answer: Option A
Q88
int x, array [10]; From the sample above, which o the following is not a valid initialization for ptr?
  • A int *ptr = *array;
  • B int *ptr = 9 + array;
  • C int *ptr = &x;
  • D int *ptr = ptr = (int *) 0xa1000;
Answer: Option A
Q89
int Y[4] = {5, 6, 7, 8}; Which of the following will declare a pointer variable that points to the array in the sample code above ?
  • A int *(yptr[4]) = &y;
  • B int (yptr *) [4] = &y;
  • C int (*yptr) [4] = &y;
  • D int *yptr [4] = &y;
Answer: Option C
Q90
int x [ ] = {1, 2, 3, 4, 5}; inr *pre, **ptr2; ptr = x; ptr2 = &ptr; Refering to the sample code above, how would you update x[2] to 10 using ptr2?
  • A **(ptr2 + 2) = 10;
  • B * (&ptr2 + 2) = 10;
  • C *(*ptr2 + 2) = 10;
  • D (**ptr2 + 2) = 10;
Answer: Option C
Questions and Answers for Competitive Exams Various Entrance Test