diff options
| author | hybrid <hybrid@hybridlabs.cc> | 2026-08-24 17:03:31 +0300 |
|---|---|---|
| committer | hybrid <hybrid@hybridlabs.cc> | 2026-08-24 17:03:31 +0300 |
| commit | 74d87fb09c1613f1118ed0159ab077bdac10be21 (patch) | |
| tree | e56edf585eb21292f4dc47d1ff5d0c7d5e9f5eb6 /src | |
| parent | e61e04619d0c9dd4d079532eff3483e234fc8acd (diff) | |
| download | learncpp-74d87fb09c1613f1118ed0159ab077bdac10be21.tar.gz learncpp-74d87fb09c1613f1118ed0159ab077bdac10be21.tar.bz2 learncpp-74d87fb09c1613f1118ed0159ab077bdac10be21.zip | |
add: naming.cppmain
Diffstat (limited to '')
| -rw-r--r-- | src/chapter1/lesson7/naming.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/chapter1/lesson7/naming.cpp b/src/chapter1/lesson7/naming.cpp new file mode 100644 index 0000000..70256b2 --- /dev/null +++ b/src/chapter1/lesson7/naming.cpp @@ -0,0 +1,59 @@ +#include <iostream> +#include <ostream> + +/* + * Question #1 + * + * Based on how you should name a variable, indicate whether each variable name + * is conventional (follows best practices), unconventional (compiler will + * accept but does not follow best practices), or invalid (will not compile), + * and why. + * + */ + +int main() { + + // Assume it's obvious what we're summing + // Conventional + [[maybe_unused]] int sum {}; + + std::cout << "\"int sum {};\": conventional\n"; + + // Unconventional: starting with underscore + [[maybe_unused]] int _apples {}; + + std::cout << "\"int _apples {};\": unconventional\n"; + + // Unconventional: starting with capital character and whole identifier + // is uppercase + [[maybe_unused]] int VALUE {}; + std::cout << "\"int VALUE {};\": unconventional\n"; + + // invalid: whitespaces are not allowed + //int my variable name {}; + std::cout << "\"int my variable name {};\": invalid\n"; + + // Unconventional: starting with capital character + [[maybe_unused]] int TotalCustomers {}; + std::cout << "\"int TotalCustomers {};\": unconventional\n"; + + // invalid: reserved word used for identifier + //int void {}; + std::cout << "\"int void {};\": invalid\n"; + + // Conventional + [[maybe_unused]] int numFruit {}; + std::cout << "\"int numFruit {};\": conventional\n"; + + // invalid: starting with a number + //int 3some {}; + std::cout << "\"int 3some {};\": invalid\n"; + + // Conventional + [[maybe_unused]] int meters_of_pipe {}; + std::cout << "\"int meters_of_pipe {};\": conventional\n"; + + std::cout << "\nLook comments in source code for explanations." << std::endl; + + return 0; +} |
