This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| enum Color { RED, GREEN, BLUE }; | |
| Color r = RED, g = GREEN; | |
| int x = 1; | |
| int main() | |
| { | |
| if ( r == g ) { std::cout << "RED == GREEN"; } // false | |
| if ( x == g ) { std::cout << "x=1 == GREEN"; } // true | |
| x = RED; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| enum class Color { RED, GREEN, BLUE }; | |
| Color redColor = Color::RED; // RED -> Color::RED | |
| int num = ( int ) Color::GREEN; // RED -> ( int ) Color::RED | |
| int main() | |
| { | |
| if ( redColor == Color::GREEN ) { std::cout << "RED == GREEN"; } // false | |
| if ( num == (int) Color::GREEN ) { std::cout << "x=1 == GREEN"; } // true | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| enum class Color : char { RED, GREEN, BLUE }; | |
| enum class Mark { ONE, TWO, THREE, FOUR, FIVE }; | |
| Color redColor = Color::RED; | |
| Mark fiveMark = Mark::FIVE; | |
| int main() | |
| { | |
| cout << sizeof ( Color ) << endl; // Вывод: 1 | |
| cout << sizeof ( redColor ) << endl; // Вывод: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| const int n = 2, m = 3; | |
| int main() | |
| { | |
| int arr[n][m] = { { 3, 5, 4 }, { 8, 6, 9 } }; | |
| for ( auto& row : arr ) | |
| { | |
| for ( auto col : row ) | |
| { | |
| std::cout << col << " "; // 3 5 4 8 6 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int max ( int a, int b, int c ) | |
| { | |
| int m = ( a > b ) ? a : b; | |
| return ( m > c ) ? m : c; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| int add ( int a, int b ) { return ( a + b ); } | |
| int sub ( int a, int b ) { return ( a - b ); } | |
| int main() | |
| { | |
| using namespace std; | |
| int ( *pf ) ( int, int ) = add; | |
| cout << pf ( 3, 2 ) << endl; // Вывод: 5 | |
| cout << pf ( 4, 5 ) << endl; // Вывод: 9 | |
| pf = sub; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef CONSTANTS_H | |
| #define CONSTANTS_H | |
| namespace Constants | |
| { | |
| const double pi ( 3.14159 ); | |
| const double avogadro ( 6.0221413e23 ); | |
| } | |
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Constants | |
| { | |
| const double pi ( 3.14159 ); | |
| const double avogadro ( 6.0221413e23 ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef CONSTANTS_H | |
| #define CONSTANTS_H | |
| namespace Constants | |
| { | |
| extern const double pi; | |
| extern const double avogadro; | |
| } | |
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "constants.h" | |
| double triplePi = 3 * Constants::pi; |