Skip to content

Instantly share code, notes, and snippets.

@emandret
Created March 25, 2023 19:17
Show Gist options
  • Save emandret/c36331ba4afde0caee9f9d7da43a4237 to your computer and use it in GitHub Desktop.
Save emandret/c36331ba4afde0caee9f9d7da43a4237 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#pragma pack(1)
struct my_struct
{
unsigned char b0;
unsigned char b1;
unsigned char b2;
unsigned char b3;
unsigned char b4;
};
int main(void)
{
struct my_struct *ptr;
unsigned char buffer[5];
ptr = (struct my_struct *) buffer;
ptr->b0 = 'h';
ptr->b1 = 'e';
ptr->b2 = 'l';
ptr->b3 = 'l';
ptr->b4 = 'o';
for (int i = 0; i < 5; i++)
{
putchar(buffer[i]); // Print "hello"
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment