Pointers Questions and Answers

Practice Mode
Showing 10 of 217 questions
Q91
main ( ) { char x [25], y[25], *p = y; strcpy (x, "BIRTHDAY"); strcpy (y, "HAPPY"); p=x; strcpy (x, "Lover"); *p = 'd'; printf("p=%s\n", p); } What will be the output when the sample code above is executed ?
  • A p=DOVERDAY
  • B p=LOVERDAY
  • C p=DOVER
  • D p=BIRTHDAY
Answer: Option C
Q92
int *x;x = (int *) 15; Is the above code legal?
  • A Yes. A new memory space will be alocated to hold the number 15.
  • B No. This would assign the number 15 to an unallocated space in memory.
  • C Yes. Upon initialization, the number 15 will be stored in a special pointer memory address space.
  • D Yes. The pointer x will point at the integer in memory location 15.
Answer: Option D
Q93
Which statement correctly defines a character string with a length of 4 plus 1 for the terminating NUL?
  • A char string [ ] ;
  • B char * string;
  • C char * string [5];
  • D char string [5];
Answer: Option D
Q94
Given that a is an arrray of elements of type t, val is a 1value expression of type "pointer to t" that points to elements in a then * ++val.
  • A sets val to point to the next element in a.
  • B increments val and then references the value in a, that val points to.
  • C increments val and then references the value in a, that val points to.
  • D references the element of a that val points to.
Answer: Option B
Q95
int Y[4] = {6, y, 8, 9}; int *ptr= Y +2; printf ("%d\n", ptrl[1]); What is printed when the sample code above is executed ?
  • A 7
  • B 8
  • C 9
  • D The code will not compile.
Answer: Option C
Q96
printf ("%s\n", string); Which of the following initializations for the string variable will cause the code above to print the string "First grade actor" when executed without memory leads or memory overwrite ?
  • A char *string = malloc (100); string = "First grade actor";
  • B char string [ ]= "Hellow again"; string = "First grade actor";
  • C char *string = "Hellow again"; string = "First grade actor";
  • D char string [100]; string = "First grade actor";
Answer: Option A
Q97
# include <ctype.h> char s [ ]  = "Photo Flash"; char *ptr = s; Referring to the code above, which of the following code is the best way to convert the string s to all lower case letters?
  • A for ( ; *ptr; ptr++) { if (isalpha (*ptr) && isupper (*ptr)) *ptr = tolower (*ptr); }
  • B tolower ( ptr );
  • C for ( ; *ptr; ptr++ ) { if (isupper (*ptr)) *ptr = tolower (*ptr); }
  • D for ( ; *ptr; ptr ++) { *ptr = tolower ( *ptr); }
Answer: Option D
Q98
exern void *ptr1; extern void *ptr2; int compare ( int n ) { return ????; } What should replace the ???? in the code above to compare the first n bytes of the memory pointed to by ptrl and ptr2 and return a non-zero value if they are equal ?
  • A memcmp (ptr1, ptr2, n)
  • B strncmp ( ptr1, ptr2, n)
  • C strncmp (ptr1, ptr2, n)
  • D !memcmp (ptr1, ptr2, n)
Answer: Option D
Q99
What memory function should be used to allocate memory in which all bits are initialized to 0 ?
  • A calloc
  • B malloc
  • C alloc
  • D memalloc
Answer: Option A
Q100
What is the primary differrence between the maolloc and calloc functions ?
  • A Memory allocated by calloc doesnot need to be freed and memory allocated by malloc does.
  • B calloc returns a pointer to char and malloc returns a void pointer.
  • C calloc initializes the memory returned and malloc does not.
  • D calloc can allocate memory for an array and malloc cannot.
Answer: Option C
Questions and Answers for Competitive Exams Various Entrance Test