Strings Interview Questions

    Question 1String Representation

    How are strings stored in C?

    Question 2String Initialization

    Which of the following correctly declares and initializes a string?

    Question 3strlen() Function

    If char str[] = "C Language";, what will strlen(str) return?

    Question 4puts() Function

    What will this program print?

    #include <stdio.h> int main() { char str[] = "Hello"; puts(str); return 0; }

    Question 5strcat() Function

    What will be printed?

    #include <stdio.h> #include <string.h> int main() { char str1[20] = "Hi "; char str2[] = "C"; strcat(str1, str2); printf("%s", str1); return 0; }

    Question 6strcmp() Function

    What will strcmp("apple", "apple") return?

    Question 7gets() Function

    Why is gets() considered unsafe in C?

    Question 8strcpy() Function

    What will be printed?

    #include <stdio.h> #include <string.h> int main() { char str1[10]; strcpy(str1, "Code"); printf("%s", str1); return 0; }

    Question 9String vs Character

    Which of the following is a string constant in C?

    Question 10strchr() Function

    Which standard library function is used to find the first occurrence of a character in a string?