|
From: Per W. <pw...@ia...> - 2007-06-06 17:14:39
|
i is a pointer, i'e an address to a separate memory for storing the
integer value.
You must first assign an address to i, before you may assign an integer to
the memory area pointed to by i.
int main() {
int *i;
i = (int*)malloc(sizeof(int));
*i = 1;
printf("%d\n",*i);
free(i); // release the memory allocated with the malloc() call.
return 0;
}
/pwm
On Wed, 6 Jun 2007, Jan Mura wrote:
> Hello,
>
> I would like to ask what is wrong on the following:
>
> ...
> int *i;
> *i = 1;
> printf ("%d", *i);
>
> ...
>
> As I read in
> Brian W. Kernighan, Denis M. Ritchie it should work.
>
> But anyway in my program it prints nothing.
>
> If I delete the line
>
> *i = 1;
>
> it works properly.
>
>
>
> I am on XP Professional with Dev-Cpp.
>
>
>
> Thanks
>
>
>
> Jan Mura
>
> jan...@vo...
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|