printf(MEMORY) | How to print memory to the console

Поделиться
HTML-код
  • Опубликовано: 4 дек 2024

Комментарии • 19

  • @undefined_exception_0
    @undefined_exception_0 3 года назад +7

    Thank You Sir , your content is rare and precious on RUclips!

  • @mehmetcivan
    @mehmetcivan 2 года назад +2

    best channel i've watched on youtube. thanks

  • @shadmanahmed271
    @shadmanahmed271 Год назад +3

    Best tutor for c. Should have made a course and publish on udemy/coursera

    • @CodeVault
      @CodeVault  Год назад +2

      There are a few courses on udemy, but I prefer hosting them on RUclips or my website instead

  • @CJKuo
    @CJKuo Год назад +1

    This is so disgusting,thank you to show how the memory works

  • @davidali133
    @davidali133 Год назад +1

    I kinda expected you to explain
    typedef struct __attribute__((__packed__)) {
    int test;
    char k;
    char str[10];
    int* p;
    short sh;
    } Thing;
    Anyways, I love your series! Keep up the good work!

    • @CodeVault
      @CodeVault  Год назад

      There's a video on this but it's partially wrong, I will soon be correcting it

  • @chenwu9788
    @chenwu9788 2 года назад +3

    Can you explain why converts &t to unsigned char*, not unsigned short*, or just char*?

    • @CodeVault
      @CodeVault  2 года назад +5

      It's unsigned because we're reading each byte so the first bit doesn't represent the sign of some number.
      It's char because sizeof(char) == 1 byte so, if you do any pointer operations it will only multiply the operation by 1 (which is the same as not multiplying)... For example:
      int someVariable; // suppose the address of it is 1000000
      unsigned char* p1 = &someVariable;
      unsigned short* p2 = &someVariable;
      // Here both p1 and p2 point to the same address
      p1 = p1 + 1; // p1 is now pointing at 1000001
      p2 = p2 + 1; // p2 is now pointing at 1000002
      So, with p2, I cannot make it point to 1000001 by just addition (I'd have to cast it to a char*)

  • @throatwobblermangrove7508
    @throatwobblermangrove7508 2 года назад +1

    Awesome as always.
    Are there any plans to cover assembler?

    • @CodeVault
      @CodeVault  2 года назад +2

      If it's requested a lot I might dive into a bit of assembly

  • @景貴張
    @景貴張 2 года назад +1

    Hi, I have a question.
    In line 30, you have made “data” become the address of each byte, and print it in line 31.
    Why does it print the value store in the address but not address itself?
    Thank you.

    • @CodeVault
      @CodeVault  2 года назад +1

      data stores the value of each byte, not the address.
      data = *(((unsigned char*) &t) + i);
      That first character (the *) dereferences the whole structure and returns the value at the address. Thus printf simply prints the value stored at that address

    • @景貴張
      @景貴張 2 года назад

      Think you so much, I just missed the “ * “ outside the bracket.

    • @nikhilpradhan7404
      @nikhilpradhan7404 2 года назад

      address is not store there. * is used to dereference the value stored in the address so the value is store in data

    • @noweare1
      @noweare1 9 месяцев назад +1

      I think one of the most confusing things about c is they use to define a pointer variable using * and also use * as a dereference operator.

  • @MrNaishadh
    @MrNaishadh 3 года назад +2

    this is good..!!

  • @deltaoui
    @deltaoui 7 месяцев назад

    Nice tutorial, just one thing : I think you went too quickly on explaining the extra bytes with 00 after the last attribute of the struct. I am not sure I understand why it was added. Is it related to the fact that we always go in (8, 16, 32, 64, 128,..) in memory and you can't have something in between ?

    • @CodeVault
      @CodeVault  7 месяцев назад

      It's to do with memory alignment. Basically each struct member is always going to be allocated to a memory address divisible by its size. This improves the speed at which the CPU caches the memory (amongst other things)