Guys,
what's the main difference between a char and a string in C / C++?
Guys,
what's the main difference between a char and a string in C / C++?
The main difference is that a char is a char and a string is a (null terminated) string of chars.Originally Posted by raghu_c
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
There are a LOT of implementations of strings in c++. The best way to think of a character is a single point in memory that has a character in it, like 'A'.
When strings are implemented in c (or sometimes c++) you have multiple points in memory where each point contains a character.
Imagine a 1-d matrix/array of characters
char *str1 = "abcde\0" = [a][b][c][d][e][\0]
char str2[5] = [a][b][c][d][e][\0]
char ch = 'a' = [a]
^
*Pseudocode*
C++ generally has managed strings that will allocate memory, free memory and give you more control over the string but the underlying concept is the same.