Strings Interview Questions

    Question 1: String Representation

    How are strings stored in C?

    Question 2: String Initialization

    Which of the following correctly declares and initializes a string?

    Question 3: strlen() Function

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

    Question 4: puts() Function

    What will this program print?

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

    Question 5: strcat() 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 6: strcmp() Function

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

    Question 7: gets() Function

    Why is gets() considered unsafe in C?

    Question 8: strcpy() 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 9: String vs Character

    Which of the following is a string constant in C?

    Question 10: strchr() Function

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