On May 6, 2:50=A0pm, Ri**** <postri...@[EMAIL PROTECTED]
> wrote:
> void foo(char *s,int *x){
>
> int *f=3Dx;
> char *k=3Ds;
> *f=3D6;
> *k=3D'a';
>
> }
>
> int main(){
>
> int a[5]=3D{1,2,3,4,5};
> char *s=3D"hello world";
There's a quirk in C. The type of a string literal is a non-const
array of char's, even though you're not allowed to modify them.
Stupid, I know.
In your function above which attempts to modify a string literal, you
get a thing known as "undefined behaviour". In the C Standard,
"undefined behaviour" is a cop-out whereby the Standard says "if you
don't follow the rules, then anything can happen, you program may
work, it may not work, I don't care".
In your particular case, on your particular system, the behaviour
which is not defined by the Standard has resulted in nothing
happening. Try changing the code as follows:
char *s =3D "hello world";
to:
char s[] =3D "hello world";
Now you should see that your function can change it.


|