0
0
Cprogramming~20 mins

Character arrays - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Character Arrays Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of character array initialization
What is the output of this C program?
C
#include <stdio.h>

int main() {
    char arr[] = {'H', 'e', 'l', 'l', 'o'};
    printf("%s", arr);
    return 0;
}
ARandom characters or garbage output
BHello\0
CCompilation error
DHello
Attempts:
2 left
💡 Hint
Remember how strings are represented in C and what %s expects.
Predict Output
intermediate
2:00remaining
Length of character array with null terminator
What will be the output of this program?
C
#include <stdio.h>
#include <string.h>

int main() {
    char arr[] = "Hello";
    printf("%zu", strlen(arr));
    return 0;
}
A6
BUndefined behavior
CCompilation error
D5
Attempts:
2 left
💡 Hint
strlen counts characters until the null terminator, but does not include it.
🔧 Debug
advanced
2:00remaining
Identify the error in character array assignment
What error will this code produce?
C
#include <stdio.h>

int main() {
    char arr[5];
    arr = "Hello";
    printf("%s", arr);
    return 0;
}
AOutput: Hello
BCompilation error: array type is not assignable
CRuntime error: segmentation fault
DCompilation error: missing semicolon
Attempts:
2 left
💡 Hint
Think about how arrays and pointers work in C.
📝 Syntax
advanced
2:00remaining
Correct way to declare and initialize a character array
Which option correctly declares and initializes a character array to hold the string "Code" by explicitly including the null terminator?
Achar arr[5] = {'C', 'o', 'd', 'e'};
Bchar arr[] = "Code";
Cchar arr[5] = {'C', 'o', 'd', 'e', '\0'};
Dchar arr[4] = {'C', 'o', 'd', 'e'};
Attempts:
2 left
💡 Hint
Remember the null terminator is needed for strings in C.
🚀 Application
expert
2:00remaining
Number of elements in a character array
Given the code below, what is the value of variable count after execution?
C
#include <stdio.h>

int main() {
    char arr[] = "Programming";
    int count = sizeof(arr) / sizeof(arr[0]);
    printf("%d", count);
    return 0;
}
A12
B11
C10
DUndefined behavior
Attempts:
2 left
💡 Hint
Remember that string literals include the null terminator in arrays.