Почему можно не указывать virtual в файле реализации?
int masivA(int* a)
, этот a
- это аргумент. Он никак не привязан к массиву a
в main()
. Туда можно передать и a и b и любой другой массив. return str.c_str();
std::string
. Или выделяйте char*
вручную, через new[]
(только не забудьте указатель потом удалить в вызывающем коде). Но лучше, конечно, возвращать string и не мучатся с ручным управлением указателями. There is an implicit conversion from lvalues and rvalues of array type to rvalues of pointer type: it constructs a pointer to the first element of an array. This conversion is used whenever arrays appear in context where arrays are not expected, but pointers are:
...
std::ostream
массивы выводить не умеет, а вот указатели - вполне себе. 2) If a side effect on a memory location is unsequenced relative to a value computation using the value of any object in the same memory location, the behavior is undefined.
cout << i << i++; // undefined behavior until C++17
a[i] = i++; // undefined behavior until C++17
n = ++i + i; // undefined behavior
что тут неправильно?
#include <random>
#include <iostream>
int main()
{
auto n = 9;
auto rnd = std::random_device{};
auto gen = std::mt19937_64{rnd()};
auto dis = std::uniform_real_distribution<double>{-0.1, 0.2};
auto res = std::vector<double>{};
std::generate_n(
std::inserter(res, std::end(res)),
n,
[&](){ return dis(gen); });
for (const auto& elem: res)
{
std::cout << elem << '\n';
}
}
Почему программа каждый раз занимает различные области памяти?
/proc/sys/kernel/randomize_va_space
либо командой setarch -R
для одного конкретного процесса. Отладчик gdb по умолчанию отключает ASLR для отлаживаемых программ. fmt::print(
"┌{0:─^{2}}┐\n"
"│{1: ^{2}}│\n"
"└{0:─^{2}}┘\n", "", "Hello, world!", 20);
┌────────────────────┐
│ Hello, world! │
└────────────────────┘
char *marka_ = new char;
char* m = "Renault"