as uint16_t pointer?
each two bytes in the uint8_t represent 16 bit integer
the first number here should be 1 but it outcome as 256
#include <stdint.h>
#include <stdio.h>
int main() {
uint8_t byteArray[] = {0x00, 0x01, 0x00, 0x02, 0x00, 0x03}; // Example data
uint16_t* uint16Array = (uint16_t*)byteArray;
for (int i = 0; i < 3; i++) {
printf("uint16Array[%d] = %u\n", i, uint16Array[i]);
}
return 0;
}
Can use a union to scan through the elements
Though this should be just fine. Keep in mind that because of endianness you might get confused with the output
That's what I thought. Then If I want the first number to be 1 I should swap it like 0x01 0x00 instead of 0x00 0x01?
Ideally, it'll be better to stote numbers in u16 then scan it as u8
printf vs cout
cout uses printf() internally
so far I used cout only
That's not true afaik
They aren't talking about that. It's a topic a bit beyond you atm
Okay, but I only want to know , I use cout everywhere only , is it good?
Hmm right, this answer also says that the implementation of cout isn't specified https://stackoverflow.com/questions/62852221/does-cout-cin-internally-call-printf-scanf-like-new-calls-malloc
Обсуждают сегодня