WorksheetsQuiz
Total questions: 20
Worksheet time: 13mins
What is a string in C programming?
A variable that stores multiple values of the same data type.
A variable that stores a sequence of characters.
A sequence of characters terminated by a new line character.
A sequence of characters terminated by a null character.
Which of the following is an example of an incorrect string initialization syntax in C?
char string_ex[] = "This string";
char string_ex[20] = 'This string';
char string_ex[] = {'T','h','i','s',' ','s','t','r','i','n','g','\0'};
char string_ex[20] = {'T','h','i','s',' ','s','t','r','i','n','g','\0'};
Which of the following statements is TRUE about strings in C?
Individual string elements are accessed through loop structures.
String size does not need to be specified in string initialization.
Strings have special functions specific for their manipulation.
All of the above.
Which of the following shows the correct syntax of a string declaration in C?
char string_ex[20];
char string_ex;
string string_ex[];
string string_ex[20];
What is the placeholder for printing strlen?
%s
%zu
%d
%c
Which of the following is the correct syntax of using fgets() to save a string in C?
fgets(&string_ex, sizeof(string_ex), stdin);
fgets(string_ex, sizeof(string_ex), stdin);
fgets(string_ex[5], stdin);
fgets(&string_ex[5], stdin);
Which of the following is the correct syntax of puts() when printing a string in C?
puts();
puts(string_ex[5]);
puts(string_ex);
puts(string_ex[]);
Which of the following is the correct syntax of saving a string in C using scanf?
scanf("%c", &scan_ex[5]);
scanf("%s", &scan_ex);
scanf("%s", scan_ex);
None, you cannot use scanf to print a string in C.
Which of the following is the correct syntax of printing a string in c using printf?
printf("%s", string_ex);
printf("%c", string_ex);
printf("%c[]", string_ex);
printf("%s[]", string_ex);
Which of the following code snippets gives the following output:
HELLO world!
char a[]="hello "
char b[]="world!";
strupr(a);
puts(a,b);
char a[]="hello "
char b[]="world!";
strcat(a,b);
strupr(a);
puts(a);
char a[]="hello "
char b[]="world!";
strupr(a);
strcat(a,b);
puts(a);
char a[]="hello "
char b[]="world!";
strupr(a);
strcat(a,b);
puts(b);
Which of the following is the correct syntax to print the length of a string?
printf("string length is %d", strlen(string_ex[]));
printf("string length is %zu", strlen(string_ex));
printf("string length is %zu, strlen(string_ex[]));
printf("string length is %d", strlen(string_ex));
Which of the following is the data type returned by strlen?
float
int
unsigned float
unsigned int
In the statement strcpy(string2, string1), which one is the destination string?
string 2
string 1
In the statement strcpy(string1, string2), which one is the source string?
string 2
string 1
What is returned by strcmp if the compared strings are not equal?
zero
nonzero value
In the statement strcat(string1, string2); in which string is the resultant string of this function stored?
string1
string2
Which of the following code snippet is the correct syntax for copying these two strings from string b to string a:
char string_a[15];
char string_b[] = "No!";
strcopy(string b, string a);
strcpy(string b, string a);
strcopy(string a, string b);
strcpy(string a, string b);
Which of the following is the output of this snippet:
char string1[] = "Hi! ";
char string2[] = "Hey! ";
strcat(string2, string1);
puts(string2);
Hi!
Hey!
Hi! Hey!
Hey! Hi!
Which of the following is the result of this code snippet:
char hello[] = "Hello World!";
char hi[] = "hello world!";
printf("%d", strcmpi(hello,hi));
0
a nonnegative number
a positive number
1
Which of the following is the output of this code snippet:
char f_name[15] ;
char l_name[] = {'T','u','r','i','n','g','\0'};
strcpy(f_name,l_name);
puts(f_name);
Turing\0
Turing
T u r i n g
No ouput will be printed.
