Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Zeichen-Datentyp | Textdatentyp
Practice
Projects
Quizzes & Challenges
Quizze
Challenges
/
C++ Datentypen

bookZeichen-Datentyp

The char data type is used to store a single character, such as 'A' or 'w'. In the next chapter, we will delve into combining these characters into sequences to create words, sentences, and more. For now, let’s focus on using char for single-character storage.

main.cpp

main.cpp

copy
1234567
#include <iostream> int main() { char letter = 'G'; std::cout << letter << std::endl; }
Note
Note

char should be specified in single quotes. Even if the character you hold is a number, you should put it in single quotes, '9', not 9.

You can play with the code above to see what happens if you use double quotes or assign numbers without quotes.

The char data type and memory.

To be stored in memory, it is first converted to a number using ASCII table. The binary representation of that number is then stored in memory.
You can take a quick look at the ASCII table below (the first column is not valuable for us).

main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { // Change the number to output different symbol char symbol = 100; std::cout << symbol; }
Note
Note

If you assign a number without single quotes to a char (for example, char letter = 76), the compiler assumes that you specified a character already converted to a number.

As you can see from the table, 76 corresponds to L, so the value of letter is 'L'.

question mark

Which of the following will produce the output L when printed to the console?

Select all correct answers

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 1

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

bookZeichen-Datentyp

Swipe um das Menü anzuzeigen

The char data type is used to store a single character, such as 'A' or 'w'. In the next chapter, we will delve into combining these characters into sequences to create words, sentences, and more. For now, let’s focus on using char for single-character storage.

main.cpp

main.cpp

copy
1234567
#include <iostream> int main() { char letter = 'G'; std::cout << letter << std::endl; }
Note
Note

char should be specified in single quotes. Even if the character you hold is a number, you should put it in single quotes, '9', not 9.

You can play with the code above to see what happens if you use double quotes or assign numbers without quotes.

The char data type and memory.

To be stored in memory, it is first converted to a number using ASCII table. The binary representation of that number is then stored in memory.
You can take a quick look at the ASCII table below (the first column is not valuable for us).

main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { // Change the number to output different symbol char symbol = 100; std::cout << symbol; }
Note
Note

If you assign a number without single quotes to a char (for example, char letter = 76), the compiler assumes that you specified a character already converted to a number.

As you can see from the table, 76 corresponds to L, so the value of letter is 'L'.

question mark

Which of the following will produce the output L when printed to the console?

Select all correct answers

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 1
some-alt