Код: Выделить всё
void Dummy(const int8[] data)
{
int n = sizeof(data); // Чему равно n?
}
void main()
{
const int8 a[] = {11, 22, 33, 44, 55};
Dummy(a);
}
Код: Выделить всё
void Dummy(const int8[] data)
{
int n = sizeof(data); // Чему равно n?
}
void main()
{
const int8 a[] = {11, 22, 33, 44, 55};
Dummy(a);
}
Код: Выделить всё
const int a[] = {11, 22, 33, 44, 55};
int n = sizeof(a) / sizeof(int);
int Dummy(int *data) {
return (sizeof(data));
}
void setup() {
Serial.println(Dummy(a));
Serial.println(n);
}Код: Выделить всё
2
5хорош же стандарт, который от версии к версии меняется так кардинально...VladislavS писал(а):В С++ есть класс std::string. Можете поинтересоваться на досуге как он устроен, особенно в последних стандартах
Код: Выделить всё
void Dummy(const int8[] data)
{
int n = sizeof(data); // Чему равно n?
}
void main()
{
const int8 a[] = {11, 22, 33, 44, 55};
Dummy(a);
}
Код: Выделить всё
#include <stdio.h>
void foo(int (*a)[10])
{
printf("%zu\n", sizeof *a / sizeof **a);
(*a)[5] = 42;
}
void bar(int (&a)[10]) // С++
{
printf("%zu\n", sizeof a / sizeof *a);
a[6] = 42;
}
int main(void)
{
int a[10];
foo(&a);
bar(a); // C++
printf("%d %d\n", a[5], a[6]);
}
Код: Выделить всё
void foo(std::array<int, 8> array)
{
...
}Код: Выделить всё
template<typename Type, int Size>
void F(Type (&data)[Size])
{
data[6] = Type();
}
// Ну или для int
template<int Size>
void G(int (&data)[Size])
{
data[6] = 42;
}
Код: Выделить всё
template <typename T, std::size_t N> using naked_array_type = T [N];
Код: Выделить всё
#include <iostream>
#include <array>
void foo(auto arr)
{
for(auto &x: arr) std::cout << x << ' ';
}
std::array<int,4> a = {1,2,3,4};
std::array<int,5> b = {5,6,7,8,9};
int main()
{
foo(a);
foo(b);
return 0;
}Код: Выделить всё
void foo(auto arr)
{
for(auto &x: arr) std::cout << x << ' ';
}
Код: Выделить всё
void foo(std::array<int, 8> a)
{
}
Код: Выделить всё
void foo(std::array<int, 8> a)
{
}