Problem using string pointer

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: kailasam (kailasam.pk_at_in.bosch.com)
Date: 03/10/04


Date: Wed, 10 Mar 2004 13:23:14 +0530

Hello All,

I was writing a simple code in VC++. It looks like below

METHOD 1 :
char *str = " ADGFR";
*str = 'c';

The above simple code gives runtime error. (the memory could not be written)

But the same if we put as an array say

METHOD2:
char str[] = " " ADGFR";
*str = 'c';
we are able to modify it.

The METHOD1 works well in turbo C but not in VC++

Could you pls explain me the reason for the above

Thanks & Regards

Kailasam



Relevant Pages