This quiz will test you understanding of the concept of Strings in C programing.
Question 1
What is a string in C?
special data type
single character
array of characters terminated by a null character
pointer to an integer
Question 2
Which header file is required to use string functions like strlen() and strcpy()?
stdlib.h
string.h
stdio.h
conio.h
Question 3
What is the output?
#include <stdio.h> #include <string.h> int main() { printf("%ld", strlen("Hello")); return 0; }
4
5
6
Compilation Error
Question 4
Which of the following correctly declares a string in C?
char name = "John";
string name = "John";
char name[] = "John";
char name ={ 'J', 'o', 'h', 'n', '\0' };
Question 5
What does the '\0' character indicate in a C string?
Space
End of file
End of string
Null string
Question 6
What is the difference between strcpy() and strncpy()?
strncpy() does not require null termination
strncpy() copies only one character
strncpy() allows specifying the number of characters to copy
No difference
Question 7
Which of the following will correctly compare two strings in C?
str1 == str2
strcmp(str1, str2) == 0
str1 = str2
str1.equals(str2)
Question 8
What is the issue with this code?
char str[5]; strcpy(str, "hello");
No Issue
strcpy is deprecated
"hello" has 6 characters (including null terminator), but str can only hold 5
str must be initialized
Question 9
Which function is used to concatenate two strings in C?
concat()
append()
strcat()
join()
Question 10
What does the function strchr(str, 'a') return?
NULL
Address of first occurrence of 'a'
Address of last occurrence of 'a'
Boolean value
There are 20 questions to complete.