Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ 変数の理解 | 変数とデータ型
C++入門

book変数の理解

メニューを表示するにはスワイプしてください

変数は、データの保存と操作において重要な役割を果たします。変数を作成するプロセスには、宣言と初期化という2つの基本的なステップがあります。

main.cpp

main.cpp

example.cpp

example.cpp

copy
12345678910
#include <iostream> int main() { // Declaration is process of introducing a variable and giving it a name int x; // Initialization is the assigning a value to a declared variable. x = 25; }

また、同じ型のデータを保持する複数の変数を宣言する場合、データ型を一度だけ指定することで便利です。

命名規則

変数には意味があり、説明的な名前を付けることが、保守性と可読性の高いコードを書くために重要。

naming.h

naming.h

copy
12
int n; // Bad naming int numberOfStudents; // Good naming

C++の変数名は英字と数字を使用できるが、数字で始めることはできず、スペースや算術演算子も含めることはできない。また、予約語と同じ名前の使用は避けること。これによりコンパイルエラーが発生する可能性がある。

main.cpp

main.cpp

copy
123456789
#include <iostream> int main() { int int = 25; // Uses reserved keyword int email!number = 25; // Contains a special character int my age = 37; // Contains space int 121A = 121; // Starts with digit }
question mark

プログラミングで変数を使用する主な目的は何か。

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 3.  2

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 3.  2
some-alt