add Chapter02 examples

This commit is contained in:
Amar Mahmutbegovic
2024-04-27 21:02:06 +02:00
parent de6d74e093
commit 5af72efc42
6 changed files with 148 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <vector>
void *operator new(std::size_t count) {
printf("%s, size = %ld\r\n", __PRETTY_FUNCTION__, count);
return std::malloc(count);
}
void operator delete(void *ptr) noexcept {
printf("%s\r\n", __PRETTY_FUNCTION__);
std::free(ptr);
}
int main() {
std::vector<std::uint8_t> vec;
constexpr std::size_t n_elem = 8;
for (std::uint8_t i = 0; i < n_elem; i++) {
vec.push_back(i);
}
const auto print_array = [](uint8_t *arr, std::size_t n) {
for (std::size_t i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\r\n");
};
print_array(vec.data(), n_elem);
return 0;
}