Skip to content

Instantly share code, notes, and snippets.

View derofim's full-sized avatar

Den derofim

  • Google
  • USA
View GitHub Profile
#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;
// Print
#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
#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
}
int arrSize = 2;
int* bar = new int[arrSize];
bar[0] = 1;
bar[1] = 2;
delete[] bar;
#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
#include <iostream>
#include <new>
int main()
{
int* p = new ( std::nothrow ) int[9999 * 9999];
if ( p == nullptr ) { std::cout << "Error"; }
else
{
delete[] p;
}
#include <iostream>
union txt
{
char let; // 1 byte
char arr[4]; // 4 bytes
} qux;
int main()
{
qux.let = 'D';
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
@derofim
derofim / Lab_SLAY_GAUSSIAN.cpp
Created September 22, 2015 21:28
Lab_SLAY_GAUSSIAN.cpp
/**
input.txt
3
3 2 -5 -1
2 -1 3 13
1 2 -1 9
output.txt
3 5 4
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
using namespace std;
template<typename T>
struct not_pair