0
0
Data Structures Theoryknowledge~10 mins

String as character array in Data Structures Theory - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access the first character of the string.

Data Structures Theory
char firstChar = str[1];
Drag options to blanks, or click blank then click option'
A{0}
B(0)
C[0]
D<0>
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using parentheses instead of square brackets.
Starting index at 1 instead of 0.
2fill in blank
medium

Complete the code to get the length of the string.

Data Structures Theory
int length = str[1];
Drag options to blanks, or click blank then click option'
A.index()
B.size()
C.count()
D.length()
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using .size() which may work in some languages but not all.
Using .count() which counts occurrences of a character.
3fill in blank
hard

Fix the error in accessing the last character of the string.

Data Structures Theory
char lastChar = str[1];
Drag options to blanks, or click blank then click option'
A[str.length() + 1]
B[str.length() - 1]
C[str.length()]
D[str.length() * 1]
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using str.length() as index which is out of bounds.
Adding 1 to length causing an error.
4fill in blank
hard

Fill both blanks to create a substring from index 2 to 5.

Data Structures Theory
String sub = str[1]([2], 4);
Drag options to blanks, or click blank then click option'
A.substring
B2
C3
D.substr
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the wrong method name.
Starting at the wrong index.
5fill in blank
hard

Fill all three blanks to create a dictionary of characters and their counts from the string.

Data Structures Theory
charCount = [1](c: str[[2]] for [3] in range(len(str)))
Drag options to blanks, or click blank then click option'
Adict
Bi
Dlist
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a list instead of a dictionary.
Using a variable name other than the loop index.