Bird
0
0
DSA Cprogramming~10 mins

How Strings Work Differently Across Languages in DSA C - Code Step by Step

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

Complete the code to declare a string in C.

DSA C
char str[] = [1];
Drag options to blanks, or click blank then click option'
A"Hello";
B'Hello'
CHello
D"Hello"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings
Not enclosing the string in quotes
Adding a semicolon inside the quotes
2fill in blank
medium

Complete the code to print the string using printf.

DSA C
printf([1], str);
Drag options to blanks, or click blank then click option'
A%d
B%s
C%c
D%f
Attempts:
3 left
💡 Hint
Common Mistakes
Using %c which prints only one character
Using %d or %f which are for numbers
3fill in blank
hard

Fix the error in copying a string using strcpy.

DSA C
char dest[20];
strcpy(dest, [1]);
Drag options to blanks, or click blank then click option'
Asource
Bstrcpy
C"source"
Ddest
Attempts:
3 left
💡 Hint
Common Mistakes
Using destination as source
Using string literal instead of variable
4fill in blank
hard

Fill both blanks to create a loop that prints each character of a string until the null character.

DSA C
int i = 0;
while (str[i] [1] '\0') {
    printf("%c", str[i]);
    i[2];
}
Drag options to blanks, or click blank then click option'
A!=
B==
C++
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of !=
Decrementing i instead of incrementing
5fill in blank
hard

Fill all three blanks to create a function that returns the length of a string.

DSA C
int string_length(char *str) {
    int [1] = 0;
    while (str[[2]] != [3]) {
        length++;
    }
    return length;
}
Drag options to blanks, or click blank then click option'
Alength
Bi
C'\0'
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Not checking for '\0' correctly