Library Functions

Q1: Which standard library function will you use to find the last occurance of a character in a string in C?

A strrchr()

B strrchar()

C strnchar()

D strchar()

ANS:D - strrchr()

strrchr() returns a pointer to the last occurrence of character in a string. Example:

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

int main()
    char str[30] = "12345678910111213";
    printf("The last position of '2' is %d.\n",
            strrchr(str, '2') - str);
    return 0;
Output: The last position of '2' is 14.

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.