|
| 1 | +#include <iostream> |
| 2 | + |
| 3 | +int main() { |
| 4 | + // 1. with Latin letters |
| 5 | + int myVariable = 10; |
| 6 | + // 2. case-sensitive |
| 7 | + int MyVariable = 20; |
| 8 | + int MYVARIABLE = 30; // MYVARIABLE != MyVariable |
| 9 | + |
| 10 | + std::cout << "myVariable: " << myVariable << std::endl; |
| 11 | + std::cout << "MyVariable: " << MyVariable << std::endl; |
| 12 | + std::cout << "MYVARIABLE: " << MYVARIABLE << std::endl; |
| 13 | + |
| 14 | + // 3. with underscores (`_`) |
| 15 | + int my_variable = 40; |
| 16 | + int _private = 50; |
| 17 | + int __double_underscore = 60; |
| 18 | + |
| 19 | + std::cout << "my_variable: " << my_variable << std::endl; |
| 20 | + std::cout << "_private: " << _private << std::endl; |
| 21 | + |
| 22 | + // 4. with digits (NEVER as start) |
| 23 | + int var1 = 70; |
| 24 | + int variable123 = 80; |
| 25 | + int var_2_test = 90; |
| 26 | + // int 1var = 100; // ❌ ERROR: cannot start with digit |
| 27 | + |
| 28 | + std::cout << "var1: " << var1 << std::endl; |
| 29 | + std::cout << "variable123: " << variable123 << std::endl; |
| 30 | + |
| 31 | + // 5. arbitrarily long identifiers (every character is significant) |
| 32 | + int thisIsAVeryLongIdentifierNameThatIsStillValidInCppAndEveryCharacterMatter = 110; |
| 33 | + |
| 34 | + std::cout << "Long identifier 0: " << thisIsAVeryLongIdentifierNameThatIsStillValidInCppAndEveryCharacterMatter << std::endl; |
| 35 | + |
| 36 | + // 6. MOST Unicode characters are ALLOWED (implementation-dependent) |
| 37 | + |
| 38 | + // Common Unicode characters / USUALLY work: |
| 39 | + // - Latin extended characters |
| 40 | + // - Greek letters |
| 41 | + // - Some mathematical symbols |
| 42 | + |
| 43 | + // those / may NOT compile | ALL systems |
| 44 | + // int café = 120; // Latin extended |
| 45 | + // int α = 130; // Greek alpha |
| 46 | + // int β = 140; // Greek beta |
| 47 | + |
| 48 | + // Unicode / characters are NOT ALLOWED |
| 49 | + // int 你好 = 150; // ❌ May not work |
| 50 | + // int 😀 = 160; // ❌ Emojis are NOT allowed |
| 51 | + // int ∑ = 170; // ❌ Many mathematical symbols are NOT allowed |
| 52 | + |
| 53 | + // 7. EVERY character is significant |
| 54 | + int temp = 300; |
| 55 | + int temp_ = 310; |
| 56 | + int _temp = 320; |
| 57 | + int temp1 = 330; |
| 58 | + int temp_1 = 340; |
| 59 | + |
| 60 | + std::cout << "temp: " << temp << std::endl; |
| 61 | + std::cout << "temp_: " << temp_ << std::endl; |
| 62 | + std::cout << "_temp: " << _temp << std::endl; |
| 63 | + std::cout << "temp1: " << temp1 << std::endl; |
| 64 | + std::cout << "temp_1: " << temp_1 << std::endl; |
| 65 | + |
| 66 | + return 0; |
| 67 | +} |
0 commit comments