What is a char*
, exactly? Is it a pointer? I thought pointers had the asterisk before the identifier, not the type (which isn't necessarily the same thing)...?
The abbreviation char is used as a reserved keyword in some programming languages, such as C, C++, C#, and Java. It is short for character, which is a data type that holds one character (letter, number, etc.) of data. For example, the value of a char variable could be any one-character value, such as 'A', '4', or '#'.
In C++, the char keyword is used to declare character type variables. A character variable can store only a single character.
char *name; This means that you just declared the pointer variable where you'll store the address of the first character in your string. It gives more freedom and flexibility to your usage.
A pointer may be a special memory location that's capable of holding the address of another memory cell. So a personality pointer may be a pointer that will point to any location holding character only. Character array is employed to store characters in Contiguous Memory Location.
It is a pointer to a character. You can write either
char* bla;
or
char *bla;
It is the same.
Now, in C, a pointer to a char was used for strings: The first character of the string would be where the pointer points to, the next character in the address that comes next, etc. etc. until the Null-Terminal-Symbol \0
was reached.
BUT: There is no need to do this in C++ anymore. Use std::string (or similar classes) instead. The char* stuff has been named the single most frequent source for security bugs!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With