1

I want to know the difference between character array and string in c++.

Can any one answer to this?? Please,

Thanks Vishnukumar

2
  • I get tons of hits when I search this exact title on Google. Commented Mar 2, 2013 at 6:09
  • That question is language-agnostic, this one is specific to C++. Commented Mar 2, 2013 at 7:24

2 Answers 2

3

string is a class/object, with methods and encapsulated data.

A char array is simply a contiguous block of memory meant to hold chars.

Sign up to request clarification or add additional context in comments.

5 Comments

thank you... in char array we have to specify the size, in string it takes default 4bytes.. am i right? is this a different?
"in string it takes default 4bytes": I don't know what you mean.
i m not sure how many bytes of memory string takes. i meant 4bytes of memory.
It depends how long your string is, but you're getting into a separate question, and stackoverflow is a question and answer site, not a discussion forum, so it would be better for you to search to see if your question has already been answered, or ask a new question yourself.
when i search while asking question i didnt find duplicate one.. so i came to ask new .. i will mind this.. thank you
2

(1) char array is just a block of char type data:
e.g. char c[100]; // 100 continuous bytes are allotted to c

(2a) By string, if you mean char string then, it's little similar to array but it's allocated in the readonly segment of the memory and should be assigned to a const char*:
e.g. const char *p = "hello"; // "hello" resides in continuous character buffer

[note: char c[] = "hello"; belongs to category (1) and not to (2a)]

(2b) By string if yo umean std::string then, it's a standard library class from header and you may want to refer its documentation or search on web

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.