logo

CuriousTab

CuriousTab

Discussion


Home C Programming Strings See What Others Are Saying!
  • Question
  • The library function used to find the last occurrence of a character in a string is


  • Options
  • A. strnstr()
  • B. laststr()
  • C. strrchr()
  • D. strstr()

  • Correct Answer
  • strrchr() 

    Explanation
    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 CuriousTab.com";
       char *ptr, c = 'i';
    
       ptr = strrchr(text, c);
       if (ptr)
          printf("The position of '%c' is: %d\n", c, ptr-text);
       else
          printf("The character was not found\n");
       return 0;
    }
    

    Output:

    The position of 'i' is: 19


    More questions

    • 1. Every function must return a value

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?
      #include<stdio.h>
      
      int main()
      {
          int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
          printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
          return 0;
      }
      

    • Options
    • A. 448, 4, 4
    • B. 520, 2, 2
    • C. 1006, 2, 2
    • D. Error
    • Discuss
    • 3. What will be the output of the program assuming that the array begins at location 1002?
      #include<stdio.h>
      
      int main()
      {
          int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2}, 
                             {2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };
          printf("%u, %u, %u, %d\n", a, *a, **a, ***a);
          return 0;
      }
      

    • Options
    • A. 1002, 2004, 4008, 2
    • B. 2004, 4008, 8016, 1
    • C. 1002, 1002, 1002, 1
    • D. Error
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *p;
          p="%d\n";
          p++;
          p++;
          printf(p-2, 23);
          return 0;
      }
      

    • Options
    • A. 21
    • B. 23
    • C. Error
    • D. No output
    • Discuss
    • 5. What will be the content of 'file.c' after executing the following program?
      #include<stdio.h>
      
      int main()
      {
          FILE *fp1, *fp2;
          fp1=fopen("file.c", "w");
          fp2=fopen("file.c", "w");
          fputc('A', fp1);
          fputc('B', fp2);
          fclose(fp1);
          fclose(fp2);
          return 0;
      }
      

    • Options
    • A. B
    • B. A
      B
    • C. B
      B
    • D. Error in opening file 'file1.c'
    • Discuss
    • 6. A preprocessor directive is a message from compiler to a linker.

    • Options
    • A. True
    • B. False
    • Discuss
    • 7. Bitwise can be used to perform addition and subtraction.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 8. Which of the following statements are correct about an if-else statements in a C-program?

      1: Every if-else statement can be replaced by an equivalent statements using   ?: operators
      2: Nested if-else statements are allowed.
      3: Multiple statements in an if block are allowed.
      4: Multiple statements in an else block are allowed.

    • Options
    • A. 1 and 2
    • B. 2 and 3
    • C. 1, 2 and 4
    • D. 2, 3, 4
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      
      int addmult(int ii, int jj)
      {
          int kk, ll;
          kk = ii + jj;
          ll = ii * jj;
          return (kk, ll);
      }
      
      int main()
      {
          int i=3, j=4, k, l;
          k = addmult(i, j);
          l = addmult(i, j);
          printf("%d, %d\n", k, l);
          return 0;
      }

    • Options
    • A. 12, 12
    • B. 7, 7
    • C. 7, 12
    • D. 12, 7
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i;
          char c;
          for(i=1; i<=5; i++)
          {
              scanf("%c", &c); /* given input is 'a' */
              printf("%c", c);
              ungetc(c, stdin);
          }
          return 0;
      }
      

    • Options
    • A. aaaa
    • B. aaaaa
    • C. Garbage value.
    • D. Error in ungetc statement.
    • Discuss


    Comments

    There are no comments.

Enter a new Comment