Bird
0
0
DSA Cprogramming~10 mins

Why Strings Are a Data Structure Not Just Text in DSA C - Test Your Knowledge

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

Complete the code to declare a string variable in C.

DSA C
char name[20] = [1];
Drag options to blanks, or click blank then click option'
A'Hello'
B20
CHello
D"Hello"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings
Not using quotes at all
Using a number instead of a string
2fill in blank
medium

Complete the code to print the string stored in variable 'text'.

DSA C
printf([1], text);
Drag options to blanks, or click blank then click option'
A%d
B%c
C%s
D%f
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d or %c instead of %s
Forgetting the format specifier
3fill in blank
hard

Fix the error in the code to copy string 'source' to 'destination'.

DSA C
strcpy(destination, [1]);
Drag options to blanks, or click blank then click option'
Adest
Bsource
C&source
D*source
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping source and destination
Using & or * with source incorrectly
4fill in blank
hard

Fill both blanks to check if the first character of 'word' is 'A'.

DSA C
if (word[1] == [2]) {
    // do something
}
Drag options to blanks, or click blank then click option'
A[0]
Bword[0]
C'A'
D"A"
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes for characters
Using the whole string instead of first character
5fill in blank
hard

Fill all three blanks to create a loop that prints each character of 'str' until the null character.

DSA C
for (int i = 0; [1]; i++) {
    if (str[i] == [2]) break;
    printf("%c", [3]);
}
Drag options to blanks, or click blank then click option'
Astr[i] != '\0'
B'\0'
Cstr[i]
Di < strlen(str)
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes for '\0'
Using wrong loop condition
Printing the wrong variable