#include <stdio.h> int main() { unsigned int x = 0x12345678; unsigned char *p = (unsigned char *)&x; printf("%02x %02x %02x %02x\n", p[0], p[1], p[2], p[3]); return 0; }
The program executes on the big-endian target. The constant 0x12345678 is stored with most significant byte first: 12 34 56 78. Printing bytes in memory order (p[0] to p[3]) outputs 12 34 56 78. Host endianness is irrelevant at runtime.
The cross-compiler compiles source code into machine code for the target architecture. The host linker and debugger run on the host, and the target assembler converts assembly code to machine code but is usually part of the cross-compiler toolchain.
#include <stdio.h> volatile int *sensor = (int *)0x40000000; int main() { int value = *sensor; printf("Sensor value: %d\n", value); return 0; }
If the sensor address is wrong, reading from it returns zero or garbage. The format specifier %d is correct for int. Declaring 'value' volatile is not necessary here. The program has a main function.
void setup() {
int x = 10
if (x > 5) {
x = x + 1;
}
}The line 'int x = 10' is missing a semicolon, causing a syntax error. Using 'void' as return type and braces placement are correct. 'x' is declared properly.
int add_one(int a) { return a + 1; }
Typically, the compiler generates one instruction to add 1 to the input register and one instruction to return (branch). So, about 2 instructions.