Hi i want to know whats the different between string and character variables?
Thanks
C++: Strings and CharactersSTRINGS AND CHARACTER VARIABLES
Page 1 of 1
2 Replies - 935 Views - Last Post: 10 July 2009 - 03:16 PM
Replies To: C++: Strings and Characters
#2
Re: C++: Strings and Characters
Posted 10 July 2009 - 05:31 AM
String is a C++ class and character is just a single data type for storing a single character.
char[]/char* are faster than using strings but they're also harder to manage (the latter especially) . The string class has certain methods to perform different actions depending on what you're doing, will of course save you some time.
char[]/char* are faster than using strings but they're also harder to manage (the latter especially) . The string class has certain methods to perform different actions depending on what you're doing, will of course save you some time.
#3
Re: C++: Strings and Characters
Posted 10 July 2009 - 03:16 PM
the difference between character and string variables,
the character variable take in memory just one byte and we can put in char varible one character like:
but string is a character array termenated by null "\0" like:
remember str[5] is contain null '\0' and also u can write it zero 0
and you can also make that:
remember str[6] is not exist it a size of array and u can many functions in string.h make many operations on string like:
strcpy,strcmp and strcat and so on.
the character variable take in memory just one byte and we can put in char varible one character like:
char c='A';
but string is a character array termenated by null "\0" like:
char str[6]="dream";OR
char* str= new char[6]; str="dream";
remember str[5] is contain null '\0' and also u can write it zero 0
and you can also make that:
char str[6]; str[0]='d'; str[1]='r'; str[2]='e'; str[3]='a'; str[4]='m'; str[5]=0;
remember str[6] is not exist it a size of array and u can many functions in string.h make many operations on string like:
strcpy,strcmp and strcat and so on.
Page 1 of 1