The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 01-24-2008
JamesGoh JamesGoh is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 89
For the code I spoke of in my first post,

Code:
int *ptr=5;
the compiler (I am using gcc btw), produced one warning saying that a pointer from integer was made without a necessary typecast. (shamrock warned me of this, so this gcc output was probably expected).

I tried this

Code:
char *str="helloworld\n";
printf("string value is %s\n",*str)
and found the program compiled fine, but at runtime I got a segmentation fault error. I also found that in the first code segment, if you ignore the compiler warning and run the program straight, you get the same run-time error.

As pointers are meant to be assigned to memory locations (and point to values), with respect to this basic understanding and the fact that ASCII characters have memory addresses, aren't both code segments technically correct ??

Last edited by JamesGoh; 01-24-2008 at 07:18 PM..