You can do the same thing in C, but you should declare it of type char[], not char*, so that you can get its size with the sizeof operator:
char myArray[] = { 0x00, 0x11, 0x22 };
size_t myArraySize = sizeof(myArray); // myArraySize = 3
Answer from Adam Rosenfield on Stack Overflowhardcode byte array in C - Stack Overflow
How do i declare a byte variable? - Post.Byes
c - "byte" declaration and meaning of %s*%s%s - Stack Overflow
How to define byte array [ ] within a byte array [ ]
You can do the same thing in C, but you should declare it of type char[], not char*, so that you can get its size with the sizeof operator:
char myArray[] = { 0x00, 0x11, 0x22 };
size_t myArraySize = sizeof(myArray); // myArraySize = 3
Just for the sake of completeness, with C99 you can also use compound literals:
char *myArray = (char []) {0x00, 0x11, 0x22 };
If source code compatibility to C++ is a requirement, you better don't use this construct, because it is - afaik - not part of the C++ standard.
There is no type byte in C++. You should use typedef before. Something like
typedef std::uint8_t byte;
in C++11, or
typedef unsigned char byte;
in C++03.
The C++ type representing a byte is unsigned char (or other sign flavour of char, but if you want it as plain bytes, unsigned is probably what you're after).
However, in modern C++, you shouldn't be using raw arrays. Use std::vector<unsigned char> if your array is runtime-size, or std::array<unsigned char, N> (C++11) if your array is of static size N. You can pass these to functions via (const) references, like this:
int Analysis(std::vector<unsigned char> &InputImage, int nHeight, int nWidth);
If Analysis does not modify the array or its elements, do this instead:
int Analysis(const std::vector<unsigned char> &InputImage, int nHeight, int nWidth);
Try
class MissileLauncher
{
public:
MissileLauncher(void);
private:
unsigned char abc[3];
};
or
using byte = unsigned char;
class MissileLauncher
{
public:
MissileLauncher(void);
private:
byte abc[3];
};
**Note: In older compilers (non-C++11) replace the using line with typedef unsigned char byte;
If you want exactly one byte, uint8_t defined in cstdint would be the most expressive.
http://www.cplusplus.com/reference/cstdint/
No, there is no type called "byte" in C++. What you want instead is unsigned char (or, if you need exactly 8 bits, uint8_t from <cstdint>, since C++11). Note that char is not necessarily an accurate alternative, as it means signed char on some compilers and unsigned char on others.
Yes, there is std::byte (defined in <cstddef>).
C++ 17 introduced it.