Q1: The library function used to find the last occurrence of a character in a string is

A laststr()

B strstr()

C strrchr()

D strnstr()

ANS:C - strrchr()

Declaration: char *strrchr(const char *s, int c); It scans a string s in the reverse direction, looking for a specific character c. Example:

#include <string.h>
#include <stdio.h>

int main(void)
   char text[] = "I learn through";
   char *ptr, c = 'i';

   ptr = strrchr(text, c);
   if (ptr)
      printf("The position of '%c' is: %d\n", c, ptr-text);
      printf("The character was not found\n");
   return 0;
Output: The position of 'i' is: 19

img not found

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.