hi all...
just getting into c. trying to understand pointers. reading the C programming language book. i have a few very simple lines of code that produce:
Bus error (core dumped)
here is the code:
the cc -Wall doesnt complain. but if i run it i get the above bus error.Code:int main () { int k, *p, *m,l; k = 10; p = &k; *p = 23; // line 5 l = *p; *m = l; // problem line printf("%d\n",*m); return 0; }
if i coment out the 'problem line' it works fine. don't understand since 'line 5' is pretty much the same statement except instead of actually assigning a number i assign the 'l' variable that holds that number.
i know that if i change 'problem line' to m = &l; it works fine. i just dont understand why it wouldn't work the other way around. like in line 5.
is it because *m doesnt even have an address yet?
i'd appreciate an explanation. thanks....