C++ Programming :: OOPS Concepts - Discussion
Home > C++ Programming > OOPS Concepts > MCQs Questions Discussion
2 / 14
What statements in the following C++ program would result in compilation error?
char *buff, *data;
void main ()
{
const char* const cp = buff;
cp = data; // Line 5
*cp='a'; // Line 6
}
char *buff, *data;
void main ()
{
const char* const cp = buff;
cp = data; // Line 5
*cp='a'; // Line 6
}
ANo compilation error
BOnly Line 5
COnly Line 6
DBoth Line 5 and Line 6
Answer: Option (Login/Signup)
Show Explanation
cp = data; cp is a const variable which means it is read-only. we can not assign values to read-only variables.
*cp='a'; cp is also a const pointer (read only) and we are trying to assign value at its address which throws error at compile time.
Asked In ::
TRICK
Both Line 5 and Line 6 throws compilation errors.
cp = data; cp is a const variable which means it is read-only. we can not assign values to read-only variables.
*cp='a'; cp is also a const pointer (read only) and we are trying to assign value at its address which throws error at compile time.
Read Full Answer
Report Error
Please Login First Click Here