Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a character array named name with space for 10 characters.
C
char name[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a size smaller than needed.
Forgetting the brackets.
✗ Incorrect
The array size must be 10 to hold 10 characters.
2fill in blank
mediumComplete the code to initialize the character array word with the string "hello".
C
char word[] = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings.
Not using quotes at all.
✗ Incorrect
Strings in C must be enclosed in double quotes.
3fill in blank
hardFix the error in the code to correctly copy the string "cat" into the character array pet.
C
#include <string.h> char pet[4]; strcpy(pet, [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings.
Passing a variable name instead of a string.
✗ Incorrect
The string to copy must be a string literal in double quotes.
4fill in blank
hardFill both blanks to create a character array greeting initialized with "hi" and print it using printf.
C
#include <stdio.h> char greeting[[1]] = [2]; printf("%s\n", greeting);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting array size too small.
Using single quotes for strings.
✗ Incorrect
The array size must be 3 to hold 'h', 'i', and the null character. The string must be in double quotes.
5fill in blank
hardFill all three blanks to declare a character array text, initialize it with "ok", and print its length using strlen.
C
#include <stdio.h> #include <string.h> char [1][] = [2]; int length = strlen([3]); printf("Length: %d\n", length);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings.
Passing the string literal instead of the array to strlen.
✗ Incorrect
The array name is 'text', initialized with the string "ok", and strlen needs the array name to get length.