Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to print struct memory bytes in C

1 Answer

0 votes
#include <stdio.h>

typedef struct Info {
    int n; // 4
    short st; // 2
    char ch; // 1
    char s[5]; // 5
    int *p; // 8
} Info;



int main(void) {
    int a;
    Info inf = {812, 17, 'a', "c c++", &a};

    unsigned char data ;
    for (int i = 0; i < sizeof(inf); i++) {
        if (i % 8 == 0 && i != 0) {
            printf("\n");
        }
        data = *(((unsigned char*) &inf) + i);
        printf("%02x ", data);
    }
    
    return 0;
}



/*
run:

2c 03 00 00 11 00 61 63 
20 63 2b 2b af 55 00 00 
e8 f5 ba 61 fd 7f 00 00

*/

 



answered Dec 26, 2020 by avibootz

Related questions

1 answer 215 views
1 answer 133 views
133 views asked May 4, 2021 by avibootz
1 answer 189 views
2 answers 258 views
1 answer 163 views
163 views asked Jul 10, 2015 by avibootz
...