Jump to content

Variables

- - - - -

  • Please log in to reply
4 replies to this topic

#1
///ViNcE

///ViNcE

    Newbie

  • Members
  • PipPip
  • 18 posts
What is the difference between a string & a char??? I am confused with this & would like help.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
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.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
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.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#4
///ViNcE

///ViNcE

    Newbie

  • Members
  • PipPip
  • 18 posts
I want to say thank you everyone but my next question is about how enumeration works. Like, the difference of it with arrays???

#5
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
An enumeration is similar to a bunch of #define's -- has nothing at all to do with arrays

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