Difficulty: Easy
Correct Answer: Error
Explanation:
Introduction / Context:This focuses on the difference between a modifiable char array and the immutability of an array name as an lvalue. While you may modify the contents of a char array element by element, you cannot reassign the array variable itself to point to a different string literal after declaration.
Given Data / Assumptions:
Concept / Approach:In C, an array variable is not a pointer variable that you can reassign; it represents a fixed block of memory. You may copy into it with functions like strcpy, but assigning a new literal to the array variable is a compile-time error.
Step-by-Step Solution:
str declared as array → valid modification via str[0] = 'K'.printf prints 'Kagpur, '.Next line tries to assign to the array name → violates C constraints → compilation fails.Verification / Alternative check:If you replace the invalid assignment with strcpy(str, 'Kanpur'); then the final print could show 'anpur' from str+1.
Why Other Options Are Wrong:
Outputs implying successful reassignment ('Kagpur, Kanpur' or 'Kagpur, anpur') would require copying or using a pointer variable, not an array.'Nagpur, Kanpur': ignores the earlier modification.Common Pitfalls:Confusing arrays with pointers; trying to reassign arrays instead of copying data into them.
Final Answer:Error.
Discussion & Comments