0
0
Cprogramming~10 mins

Character arrays - Interactive Code Practice

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

Complete 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'
A5
B20
C15
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using a size smaller than needed.
Forgetting the brackets.
2fill in blank
medium

Complete 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'
A"hello"
B'h','e','l','l','o'
Chello
D'hello'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings.
Not using quotes at all.
3fill in blank
hard

Fix 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'
A'cat'
Bcat
C"cat"
Dpet
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings.
Passing a variable name instead of a string.
4fill in blank
hard

Fill 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'
A3
B"hi"
C2
D'hi'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting array size too small.
Using single quotes for strings.
5fill in blank
hard

Fill 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'
Atext
B"ok"
Dok
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings.
Passing the string literal instead of the array to strlen.