RE: [Dev-C++] Question about pointers (beginner)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Christian S. <sm...@xs...> - 2003-05-27 18:27:23
|
I just executed this code:
#include <stdio.h>
main ( )
{
int x, *ptr_int;
*ptr_int = 456;
printf ("The value of ptr_int is %p\n",ptr_int);
printf ("The value of *ptr_int is %d\n",*ptr_int);
x = 123;
ptr_int = &x;
printf ("The value of ptr_int is %p\n",ptr_int);
printf ("The value of *ptr_int is %d\n",*ptr_int);
printf ("The value of x is %d\n",x);
printf ("The value of &x is %p\n",&x);
}
And it gives me as expected 123 for x. However I would expect an error or
something like that for the line: *ptr_int = 456;
as *ptr_int is not linked to any memory address at that time. Anyway maybe
it was a error in the book when they stated that the end result of x should
be 456 instead of 123 as I expected.
|