2011년 8월 9일 화요일

Using Pointer in C

Execution Environment :: VS2010


// #1 type conflict :: warning, runtime error
char *sptr = "abc", *tptr;
*tptr = sptr;
printf("%s\n", tptr);

// #2 type matched :: no error
char *sptr = "abc", *tptr;
tptr = sptr;
printf("%s\n", tptr);

// #3 not-allocated memory space :: runtime error
char *sptr = "abc", *tptr;
*tptr = *sptr;
printf("%s\n", tptr);

// #4 constant integer allocation in integer pointer :: runtime error
int *iptr = (int *)10;
*iptr = 11;
printf("%d\n", *iptr);

// #5 type conflict :: warning, runtime error
int *iptr = 10;
*iptr = 11;
printf("%d\n", *iptr);

// #6 soon fixed :: no error
int *iptr = (int *)10;
iptr = NULL;

댓글 없음:

댓글 쓰기