Question: i have some doubts regarding character pointers:

1.when we write the declaration:

```
char *t;

```

do we need to do 

```
t=new char[6];
strcpy(t,"terry");

```

or directly 

```
 t="terry";

```

will do..

2.Also if we follow do

```
char *t;
t=new char[6];
t="terry";

```

will t now point to the allocated memory from heap or the first letter of terry(if we look from the point of view of manipulation of pointers).

3.if i write:

```
char *t;

```

and then i have to initialise 't' to '\0'(but t should point to an allocated memory space)..how do i do this because my mvc 2010 compiler doesnt allow...

```
t=new char[5](0);//0 is the ascii value of '\0'

```

Answer: 
You're tagged C++. Use string:

`std::string t("terry");` and let the language take care of the details for you.

1. Either way will do, depending on your needs. If you need to change the string later you have to allocate the memory, and when you allocate always remember to delete it later.
2. The first letter of the literal.
3. `t=new char[5]; t[0] = 0;`
**1.** If the string (e.g. "terry") is not going to get changed anywhere in you program, you can surely do

```
char* t = "terry";

```

and forget about the memory allocated for the string as it will be freed on its own. However, a better programming practice for constant strings would be declaring `t` as `const char*` like this:

```
const char* t = "terry";

```

But if it is going to get changed, then it's either

```
char* t = new char[6];
strcpy(t, "terry");

```

or

```
char t[6];
strcpy(t, "terry");

```

In the first case, where `new` operator is used, you will have to free the memory allocated with `new` after you no longer need the string:

```
delete[] t;

```

In the second case, the memory underlying the sting will be freed automatically when `t` leaves the C++ scope (curly braces) it was declared in (but if `t` is a member of an object, the memory will be freed only when the object is destructed).

**2.** After

```
char* t;
t = new char[6];
t = "terry";

```

`t` would really point at "terry", but the pointer/address you would need to free the memory allocated with `new` is lost for good.

**3.** String null terminators ('\0') are just like other characters: they need reside somewhere in the memory. You were wise enough to allocate 6 bytes for "terry", which is 5 characters in length: after

```
char* t = new char[6];
strcpy(t, "terry");

```

the 6th byte of the memory block pointed by `t` holds the null terminator. But

```
char* t;

```

does not allocate any memory apart from the `t` pointer. So, if you want a string to contain only a null terminator (be zero-length), you could do it in this way:

```
char* t = new char[1];
t[0] = '\0';

```