Quiz: Arrays | Strings
Quiz: Arrays | Strings checks how well you can apply Index of first and last element and Null terminator in strings (and related ideas) in C.
Introduction
Quiz: Arrays | Strings checks how well you can apply Index of first and last element and Null terminator in strings (and related ideas) in C. Try each prompt in a scratch file before moving on.
Understanding the topic
Challenge 1 In your own words — or with a tiny program — show that you understand: Index of first and last element.
Challenge 2 In your own words — or with a tiny program — show that you understand: Null terminator in strings.
Challenge 3 In your own words — or with a tiny program — show that you understand: sizeof array vs pointer.
Challenge 4 In your own words — or with a tiny program — show that you understand: strcpy vs strncpy safety.
- Challenge 1 — In your own words — or with a tiny program — show that you understand: Index of first and last element.
- Challenge 2 — In your own words — or with a tiny program — show that you understand: Null terminator in strings.
- Challenge 3 — In your own words — or with a tiny program — show that you understand: sizeof array vs pointer.
- Challenge 4 — In your own words — or with a tiny program — show that you understand: strcpy vs strncpy safety.
Step-by-step explanation
- Challenge 1 — In your own words — or with a tiny program — show that you understand: Index of first and last element.
- Challenge 2 — In your own words — or with a tiny program — show that you understand: Null terminator in strings.
- Challenge 3 — In your own words — or with a tiny program — show that you understand: sizeof array vs pointer.
- Challenge 4 — In your own words — or with a tiny program — show that you understand: strcpy vs strncpy safety.
Execution workflow
Challenge 1
In your own words — or with a tiny program — show that you understand: Index of first and last element.
Best practices
- Enable warnings: gcc -Wall -Wextra -std=c11 source.c -o app
- Give every variable a defined value before it is read.
- Stay inside array bounds — C will not stop you from over-running a buffer.
Common mistakes
- Reading uninitialized storage — behavior is undefined.
- Dismissing compiler warnings instead of fixing root causes.
- Ignoring NULL returns from malloc, fopen, and similar APIs.
Hands-on exercise
Practice problems:
- Build or explain: Index of first and last element
- Build or explain: Null terminator in strings
- Build or explain: sizeof array vs pointer
- Build or explain: strcpy vs strncpy safety
Summary
Quiz: Arrays | Strings in C — Self-check on indexing and C strings.