Quiz 12
Quiz 12
MAbdullah
Name: _____________________________ 133715
Roll No: _____________________________
Question 1: [2x8 marks] [estimated time 8 minutes] char color [] = {'b', 'l', 'u', 'e'};
Supply the missing words to complete the statements.
b) (T / F) Printing a string that does not contain a
1. A string is accessed via a to the string’s first terminating null character is a logic error—program
character. ___________________.
pointer execution terminates immediately.
2. What is the right way to initialize an array? c) (T / F) Function strcpy copies its first argument
int num[6] = { 2, 4, 12, 5, 45, 5 }; (a string) into its second argument,
int n {} = { 2, 4, 12, 5, 45, 5 }; d) (T / F) strcmp (s1, s2) return 0 if s1 and s2
int n{6} = { 2, 4, 12 }; strings are equal
int n(6) = { 2, 4, 12, 5, 45, 5 }; e) (T / F) PUTS can print a multi-word string.
3. int iscntrl (int c); Returns a true value if c f) (T / F) String is an array of Characters with a
___________
is a control character. null character as the last element of an array.
4. int isgraph (int c); Returns a true value if c is a
Question 3: [2x5 marks] [estimated time 6 minutes]
space
printing character other than a ________________ Dry Run the pseudocode and write the expected
5. Which function is described as “Returns a true value output against the input. (Write “Blank” for no output
or write “compile Error” if there is any error).
if the argument character is a digit or a letter;
otherwise, returns 0 (false)”? 1. Write the output of each printf in a separate line
given at the end:
a) isalnum.
b) isdigit. #include<stdio.h>
isalpha ('$')? "$ is a ": "$ is not a ", "letter", char s3[50] = "";
printf("%c%s", toupper(s1[0]), &s1[1]);
$ is not a letter".
____________________________________
printf("%s", strcpy(s3, s2));
7. In the context of function strtok, a is a sequence of printf("%s", strcat(strcat(strcpy(s3, s1), " and "), s2));
token
characters separated by delimiters ______________.
printf("%zu", strlen(s1) + strlen(s2));
8. What is the maximum length of a C String. printf("%zu", strlen(s3)); // using s3 after part executes
_________________________?
Not a fxed lenght }
Output: ___________________________
jack
Question 2: [1x6 marks] [estimated time 6 minutes]
In the following questions mark True or False.
jill
Output: ___________________________
a) (T / F) The following definition initializes the
color array to the character string "blue": jack and jill
Output: ___________________________
Quiz 12 – Chapter 08 - Characters and Strings Page 1 of 2
CC-112 Programming Fundamentals Spring 2022
8
Output: ___________________________ Input string: If Life were predictable it would cease to be
life and be without the flavor.
13
Output: ___________________________ Search string: be
Expected Output: 2
2.
_____________________________________________
_____________________________________________