Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a `char*`?

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)...?

like image 894
Maxpm Avatar asked Nov 27 '10 20:11

Maxpm


People also ask

What is a char * in C?

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 '#'.

What is a char C++?

In C++, the char keyword is used to declare character type variables. A character variable can store only a single character.

What does char * a means?

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.

What is a char pointer in C?

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.


1 Answers

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!

like image 121
Lagerbaer Avatar answered Oct 15 '22 20:10

Lagerbaer