Govt Exams
arr creates a modifiable array copy of the string. ptr points to a string literal (read-only in memory). Modifying *ptr leads to undefined behavior.
strcpy() doesn't check dest buffer size, making it unsafe. It can cause buffer overflow if src is larger than dest. Modern compilers recommend strncpy() or strlcpy().
arr[0][0] is a 1D array of 5 integers. Each int is 4 bytes, so total is 5×4=20 bytes.
Both strtok() (modifies by replacing delimiters with '\0') and strcpy() (copies and overwrites destination) modify strings in-place.
This expression calculates array length. sizeof(arr) gives total bytes (40 on 32-bit system), sizeof(arr[0]) gives bytes per element (4), so 40/4=10.
C uses row-major order for 2D arrays. matrix[0][0], matrix[0][1]...matrix[0][4], matrix[1][0]... are stored sequentially in memory.
strlen() counts characters before the null terminator. "C2025" has 5 characters, so strlen returns 5. The null terminator is not counted.
"Hello" has 5 characters, so valid indices are 0-4. Index 5 contains the null terminator '\0' that marks the end of the string.
Array names decay to pointers to the first element in expressions, but they are not truly pointer variables. The array name cannot be reassigned.
Both syntax forms are valid in C. Elements can be provided in nested braces or as a linear list, and they fill row by row.