Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!ccu.umanitoba.ca!salomon From: salomon@ccu.umanitoba.ca (Dan Salomon) Newsgroups: comp.lang.c Subject: Re: confusion with char *a and char a[NUM] Message-ID: <1990Dec4.214845.18949@ccu.umanitoba.ca> Date: 4 Dec 90 21:48:45 GMT References: <7656@umd5.umd.edu> Distribution: na Organization: University of Manitoba, Winnipeg, Canada Lines: 28 In article <7656@umd5.umd.edu> jjk@astro.umd.edu( Jim Klavetter) writes: > >I can have two identical files except that one I declare a to be > char a[NUM] >and the other has > char *a with a malloc of NUM+1 characters. > ... >However, if I have > a=strchr(string, ":"); >I get the error message > 121: incompatible types in assignment > No big mystery. char a[NUM]; declares "a" to be a constant pointer to an array of char that points to the region allocated by the compiler. Hence you cannot change its value. char *a; declares a to be a variable pointer to an array of char. This treatment allows the optimization of array accesses with constant subscripts. -- Dan Salomon -- salomon@ccu.UManitoba.CA Dept. of Computer Science / University of Manitoba Winnipeg, Manitoba, Canada R3T 2N2 / (204) 275-6682 Brought to you by Super Global Mega Corp .com