Hi,
i dont understand the following; PLZ fix me.
when i try to change the character pointed by pointer the behaviour is undefined.
but when i change the same by using pointer as formal parameter of function it will be ok.
why i cant change the base address of array, when i can change the pointer value.
int main()
{
char *ptr = "String";
char arr[]= "Array";
*str ='T'; // behaviour is undefined
arr = ptr; // not allowed
modify(arr);
return 0;
}
int modify(char *p)
{
*p = 'X';// no problem
}
the second problem is
2.
int main()
{
printf("Hello" "World"); // HelloWorld
printf("%s%s","Hello" "World"); // HelloWorld(someGarbage)
return 0;
}
how first printf printing o/p: HelloWorkld ( why concatenating).
The printf should stop priting whenever it finds first '\0'.
and the second printf printing some garbages after the strings.
Thanks,
Danian.