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 = new int* [n]; | |
| for ( int i = 0; i < n; ++i ) { arr[i] = new int[m] (); } | |
| arr[0][1] = 3; | |
| arr[1][1] = 4; | |
| arr[1][2] = 8; | |
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 = new int[n * m](); | |
| // arr[i][j] --> arr[i*m+j] | |
| arr[0] = 2; // 0 * m + 0 | |
| arr[1] = 3; // 0 * m + 1 | |
| arr[3] = 8; // 1 * m + 0 | |
| arr[5] = 9; // 1 * m + 2 |
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> | |
| void* operator new ( std::size_t sz ) | |
| { | |
| std::cout << sz << " bytes"; | |
| return std::malloc ( sz ); | |
| } | |
| int main() | |
| { | |
| int* p1 = new int; // Вывод (MVS, x64): 4 bytes | |
| } |
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 arrSize = 2; | |
| int* bar = new int[arrSize]; | |
| bar[0] = 1; | |
| bar[1] = 2; | |
| delete[] bar; |
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 <stdlib.h> | |
| #include <crtdbg.h> | |
| #define CRTDBG_MAP_ALLOC // Настройка для вывода файла и строки | |
| #define new new( _NORMAL_BLOCK, __FILE__, __LINE__) // Для вывода файла и строки с утечкой | |
| void main() | |
| { | |
| _CrtMemState _ms; // Текущее состояние памяти | |
| _CrtMemCheckpoint ( &_ms ); // Проверка начиная с состояния _ms | |
| int* leak = new int[20]; // Утечка памяти: Нет delete[] leak; | |
| _CrtMemDumpAllObjectsSince ( &_ms ); // Вывод утечек памяти в Output |
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> | |
| #include <new> | |
| int main() | |
| { | |
| int* p = new ( std::nothrow ) int[9999 * 9999]; | |
| if ( p == nullptr ) { std::cout << "Error"; } | |
| else | |
| { | |
| delete[] p; | |
| } |
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> | |
| union txt | |
| { | |
| char let; // 1 byte | |
| char arr[4]; // 4 bytes | |
| } qux; | |
| int main() | |
| { | |
| qux.let = 'D'; |
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
| inline double fd() { return 1.0; } | |
| extern double d1; | |
| double d2 = d1; // unspecified: // 0.0 or 1.0 | |
| double d1 = fd(); // may be initialized statically or dynamically to 1.0 |
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
| /** | |
| input.txt | |
| 3 | |
| 3 2 -5 -1 | |
| 2 -1 3 13 | |
| 1 2 -1 9 | |
| output.txt | |
| 3 5 4 | |
| */ |
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> | |
| #include <fstream> | |
| #include <string> | |
| #include <vector> | |
| #include <set> | |
| using namespace std; | |
| template<typename T> | |
| struct not_pair |