|
From: Jan M. <jan...@vo...> - 2007-06-07 06:39:20
|
Well, of course. Maybe I am a little bit out of order because of dealing
with C and its pointers now quite intensively.
Thank you anyway
Jan Mura
----- Original Message -----
From: "Per Westermark" <pw...@ia...>
To: "Jan Mura" <jan...@vo...>
Cc: <dev...@li...>
Sent: Wednesday, June 06, 2007 7:13 PM
Subject: Re: [Dev-C++] What is wrong
> 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
> >
>
>
>
> __________ Informace od NOD32 2313 (20070606) __________
>
> Tato zprava byla proverena antivirovym systemem NOD32.
> http://www.nod32.cz
>
>
|