What is the difference between a string & a char??? I am confused with this & would like help.
4 replies to this topic
#1
Posted 29 January 2012 - 01:16 PM
|
|
|
#2
Posted 29 January 2012 - 01:22 PM
A string is a sequence of char's, in C, or a class that represents the same, in C++. A char is a single ascii/unicode character.
#3
Posted 29 January 2012 - 01:52 PM
To expand a little on what ^^^ said, a string is a sequence of chars, for example "Hello World". A char is a single char, such as the 'H' in the previous string.
>>A char is a single ascii/unicode character
UNICODE does't have char, but has something similar with is wchar_t, you can use char in UNICODE programs but they are identical to char in standard ascii programs. sizeof(wchar_t) > sizeof(char). The size of wchar_t is normally 2 on MS-Windows and 4 on *nix. I haven't checked the UNICODE standard committee recently but the last time I checked there was some discussion of expanding wchar_t to 16 so that it can accommodate some languages such as Chinese that use graphics glyphs.
>>A char is a single ascii/unicode character
UNICODE does't have char, but has something similar with is wchar_t, you can use char in UNICODE programs but they are identical to char in standard ascii programs. sizeof(wchar_t) > sizeof(char). The size of wchar_t is normally 2 on MS-Windows and 4 on *nix. I haven't checked the UNICODE standard committee recently but the last time I checked there was some discussion of expanding wchar_t to 16 so that it can accommodate some languages such as Chinese that use graphics glyphs.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#4
Posted 29 January 2012 - 06:11 PM
I want to say thank you everyone but my next question is about how enumeration works. Like, the difference of it with arrays???
#5
Posted 29 January 2012 - 07:37 PM
An enumeration is similar to a bunch of #define's -- has nothing at all to do with arrays
Example:
The above just defines 4 integers with names, you can do similar with defines
One nice feature about enums is that you can pass one to a function by the name of the enum instead of by its individual value
Example:
enum colors {red = 1, blue, black, yellow};
The above just defines 4 integers with names, you can do similar with defines
#define red 1 #define blue 2 #define black 3 #define yellow 4
One nice feature about enums is that you can pass one to a function by the name of the enum instead of by its individual value
int foo(colors color)
{
switch(color)
{
case red: // blabla
case blue:
case black:
case yellow:
}
}
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









