Ravindu
Ravindu

Reputation: 2550

What does (char)0 mean in c++?

What is the meaning of (char)0.

For example what does this mean?

array[1] = (char)0;

Upvotes: 2

Views: 7921

Answers (3)

Attila
Attila

Reputation: 28762

You are casting an int (integer) (0) to a character (char).

Casting means you are changing the type.

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799014

It's 0 casted to a char, which is '\0'.

Upvotes: 2

Etienne de Martel
Etienne de Martel

Reputation: 36986

It's a C-style cast. That is, it converts 0 (which is a literal of type int) to char (the \0 character). That cast could have been avoided entirely by simply using the '\0' literal.

Upvotes: 6

Related Questions