LearnFrenzy
Sign in Take a free test

Strings · Exercise 1 of 4

Strings String Basics MCQ

  • 12 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twelve multiple-choice questions on how C strings work: the terminator, literals vs arrays, safe input, string.h, ctype, UTF-8 and C23. Pick an option to check your answer instantly.

Question 1 Easy

How many bytes does char s[] = "Hello"; occupy?

A 5
B 6
C 4
D 8
Question page & discussion
Question 2 Hard

What happens with char s[5] = "Hello"; in C?

A It does not compile in C
B It compiles, but s has no '\0', so it is not a valid string
C The compiler makes the array 6 bytes
D The last letter is replaced by '\0'
Question page & discussion
Question 3 Easy

Why was gets() removed from the C standard in C11?

A It was too slow
B It cannot limit input to the buffer size, so it always risks a buffer overflow
C It could not read spaces
D It was replaced by scanf()
Question page & discussion
Question 4 Medium

Which statement about char *p = "hi"; and char a[] = "hi"; is true?

A Both can be modified safely
B a is a writable copy; modifying the literal through p is undefined behaviour
C p is a copy; a points to the literal
D sizeof p == sizeof a
Question page & discussion
Question 5 Easy

What does strcmp(a, b) return when a comes before b?

A Exactly -1
B Some negative value
C 0
D false
Question page & discussion
Question 6 Medium

After char d[4]; strncpy(d, "LearnFrenzy", 4);, what is true?

A d holds "Lea" and '\0'
B d holds "Lear" with no '\0'
C d holds the whole string
D strncpy() returns an error
Question page & discussion
Question 7 Easy

Which function writes formatted text into a buffer without ever overflowing it?

A sprintf()
B strcat()
C snprintf()
D strcpy()
Question page & discussion
Question 8 Medium

Which statement about strtok() is true?

A It leaves the input string unchanged
B It writes '\0' into the string and keeps hidden state between calls
C It returns empty tokens for ",,"
D It works on string literals
Question page & discussion
Question 9 Hard

Why is toupper((unsigned char) c) recommended over toupper(c) for a char c?

A It is faster
B A plain char may be negative for bytes above 127, and passing a negative value (other than EOF) is undefined behaviour
C toupper() only accepts unsigned types
D It changes the result for ASCII letters
Question page & discussion
Question 10 Medium

Source files are UTF-8. What does strlen("héllo") return?

A 5
B 6
C 10
D It does not compile
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Popular