Pointers Questions and Answers

Take Exam

Pointers questions with answers are a crucial part of C programming preparation, often included in technical interviews and MCQ-based exams. Pointers are variables that store the memory address of other variables, making them fundamental to dynamic memory management and efficient program design. These C programming MCQ questions and answers help students understand pointer arithmetic, function pointers, arrays, and memory allocation. Commonly asked in placement exams by TCS, Infosys, and Wipro, mastering pointer concepts gives you a competitive edge in coding tests and programming interviews.

Pointers

Showing 10 of 217 questions

91. 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 ?

  • p=DOVERDAY
  • p=LOVERDAY
  • p=DOVER
  • p=BIRTHDAY
Show Answer Report

92. int *x;x = (int *) 15; Is the above code legal?

  • Yes. A new memory space will be alocated to hold the number 15.
  • No. This would assign the number 15 to an unallocated space in memory.
  • Yes. Upon initialization, the number 15 will be stored in a special pointer memory address space.
  • Yes. The pointer x will point at the integer in memory location 15.
Show Answer Report

93. Which statement correctly defines a character string with a length of 4 plus 1 for the terminating NUL?

  • char string [ ] ;
  • char * string;
  • char * string [5];
  • char string [5];
Show Answer Report

94. 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.

  • sets val to point to the next element in a.
  • increments val and then references the value in a, that val points to.
  • increments val and then references the value in a, that val points to.
  • references the element of a that val points to.
Show Answer Report

95. 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 ?

  • 7
  • 8
  • 9
  • The code will not compile.
Show Answer Report

96. 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 ?

  • char *string = malloc (100); string = "First grade actor";
  • char string [ ]= "Hellow again"; string = "First grade actor";
  • char *string = "Hellow again"; string = "First grade actor";
  • char string [100]; string = "First grade actor";
Show Answer Report

97. # 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?

  • for ( ; *ptr; ptr++) { if (isalpha (*ptr) && isupper (*ptr)) *ptr = tolower (*ptr); }
  • tolower ( ptr );
  • for ( ; *ptr; ptr++ ) { if (isupper (*ptr)) *ptr = tolower (*ptr); }
  • for ( ; *ptr; ptr ++) { *ptr = tolower ( *ptr); }
Show Answer Report

98. 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 ?

  • memcmp (ptr1, ptr2, n)
  • strncmp ( ptr1, ptr2, n)
  • strncmp (ptr1, ptr2, n)
  • !memcmp (ptr1, ptr2, n)
Show Answer Report

99. What memory function should be used to allocate memory in which all bits are initialized to 0 ?

  • calloc
  • malloc
  • alloc
  • memalloc
Show Answer Report

100. What is the primary differrence between the maolloc and calloc functions ?

  • Memory allocated by calloc doesnot need to be freed and memory allocated by malloc does.
  • calloc returns a pointer to char and malloc returns a void pointer.
  • calloc initializes the memory returned and malloc does not.
  • calloc can allocate memory for an array and malloc cannot.
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test