0
Can anyone pls explain the use of string, char ,and bool
7 Antworten
+ 5
string char and bool are 3 data type of variable.
bool use less memory space than other and have 2 only state true and false,
char use only 1 byte and the max lenght is 1 character
string is an array of char so it takes as much space as the character contained.
ex. string dog="mark"; use 4 char so it takes 1*4byte of space.
you can use any type you want in your program but to write better code it's essential to reduce the space of the variable used as much as possible.
ex. if you can solve a situation with a bool variable is better than a string. because your code can be putted inside a loop in another loop so your 4 character string become 4 byte *100*100= 40.000 byte vs 10.000
it doesn't seem much but if you think this on a large scale can be catastrophic for a big project :)
Sorry for my bad english as you probably understand is not my main language :)
+ 1
String use double quotation "C" (Number,characters,symbols) and it's a part of standard library <string>
Characters use a single quotation ' C ' (single letter,symbols) and holds a 1-byte integer
Booleans we use bool and hold two value true and false
0
char is used for storing character data,bool for data storage for lower decimal values like eg:0.053664
0
String treats the input as letters. Character refers to a single letter within a string (words). Boolean is either a True or False value.
0
String is for letter and words!
- 1
What is character data? What is string?
- 5
string is probably for numbers