What is wrong with the following code segment, assumming it compiles correctly?
char *a = "Hello";
char *b = " Mom";
while( *b != '\0' ) {
*a = *b;
a++;
b++;
}
If your code compiles correctly then it is your logical error.
Here you can not write *a = *b like this as normal variable.
As you are assigning a value of pointer b to pointer a you must write like *a == *b;
*a = *b will give you segmentation fault.
while *a == *b works correctlly.
Get Answers For Free
Most questions answered within 1 hours.