1. Basic Concepts
What are Char Arrays?
- Definition: A sequence of characters terminated by null character (
'\\0')
- Lower-level representation: Inherited from C language
- Memory: Fixed size, contiguous memory allocation
char str[] = "hello"; // Automatically adds '\\0' at end
char arr[100]; // Declares array of 100 characters
Key Characteristics
- Null Termination: Every char array ends with
'\\0'
- Fixed Size: Fixed size (cannot grow or shrink after declaration)
- Manual Management: No automatic memory handling
2. Input Issues & Solutions
Problem with cin
// ❌ PROBLEM: cin stops at space, tab, or newline
char name[100];
cin >> name; // Input: "Vishal Rajput" → Only stores "Vishal"
Why? The cin object has delimiters for:
\\n (Enter)
\\t (Tab)
- (Space)
It stops inserting data after encountering these delimiters.
Solutions