Discussion
Consider the following 'C' program fragment :
int main( )
{
char *a, *b, c[10], d[10];
a=b;
b=c;
c=d;
d=a;
return φ;
}
Choose the statement having error from the following :
Answer: C
The statements with errors are c=d; and d=a;.
In C, an array name such as c or d is not a modifiable lvalue: it stands for the fixed address of the array, so an array cannot be assigned to. Both c=d (array to array) and d=a (pointer to array) are therefore compilation errors.
a=b assigns one char pointer to another, and b=c assigns the address of c's first element to a pointer (the array name decays to a pointer), so both are legal. Every option that names a=b or b=c as an error is wrong.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development