Checksum: 51173 Path: utzoo!utgpu!romwa From: romwa@gpu.utcs.toronto.edu (Mark Dornfeld) Date: Tue, 11-Oct-88 14:37:28 EDT Message-ID: <1988Oct11.143728.28627@gpu.utcs.toronto.edu> Organization: University of Toronto Computing Services Subject: string assignment in C Newsgroups: comp.lang.c I've been reading a book on /rdb recently. In the book they have a small example where they assign strings. char *p1="first"; char *p2; main( argc, argv ) int argc; char *argv[]; { p2 = " is:"; } The assignment to p1 makes sense to me, because the compiler could set aside the size of the string being assigned. The second case baffles me. I always thought that you had to give a string a "maximum size" and then use strcpy or sprintf for assignment. Isn't the assignment of p2 a dangerous thing to do since the compiler has (presumably) only left enough space for the pointer and not for the string. I tried this example out on QuickC and everything worked. i.e. printf'ing p2 gives 'is:'. Could someone please shed some light on this for me. Could you also please respond via e-mail, since I am borrowing someone's account in order to post this. advTHANKSance Pavneet Arora ...!utgpu!rom!pavneet Royal Ontario Museum 100 Queen's Park Toronto, Ontario M5S 2C6 (416) 585-5626