String literals and string initializations

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ย. 2024
  • Initializing strings in C can be quite confusing sometimes. Do you use char* or char[] and what are the differences? We'll find out in this video.
    Feel free to ask questions in the comments below!
    ---
    IDE used in the video: sourceforge.ne...
    Check out my course over on Udemy: www.udemy.com/...

ความคิดเห็น • 11

  • @syedyousufhussain2725
    @syedyousufhussain2725 3 ปีที่แล้ว +2

    please bro don't stop making videos your videos are awesome your videos will be very helpful for all beginners who watch your videos you just explain things very simply and deeply

  • @agariogg172
    @agariogg172 3 ปีที่แล้ว +3

    Man, your channel is honestly amazing, thanks for this ultra useful content.

  • @reshmaimmaculater.4868
    @reshmaimmaculater.4868 3 ปีที่แล้ว +1

    You should write a book with all your insights. So cool!

  • @mpi6416
    @mpi6416 2 ปีที่แล้ว +1

    Very good and clear. Thank you very much

  • @noweare1
    @noweare1 7 หลายเดือนก่อน

    I was always confused about the difference and when to use char * var or char var[ ], thanks

  • @lilyscarlet2584
    @lilyscarlet2584 3 ปีที่แล้ว +2

    c strings are stored in a read only static memory section and when you use array syntax it just copies it into a buffer on the stack where when you use char* it is just a reference to that read only static memory that cant be modified.

    • @CodeVault
      @CodeVault  3 ปีที่แล้ว

      Not quite. The part about using char* is correct and, most of the time C strings are just a reference to that read-only part of memory. But there's a special case when using string literals at initialization of a char array:
      char arr[] = "Test";
      Is just syntactic sugar for:
      char arr[] = {'T', 'e', 's', 't', '\0'};
      And doesn't actually save that string "Test" into the read only memory.
      Although I can't say this as a definite answer as there might be different implementations of this in certain compilers

    • @lilyscarlet2584
      @lilyscarlet2584 3 ปีที่แล้ว

      @@CodeVault yeah you are right i forgot to mention that

  • @johnjiangtw0804
    @johnjiangtw0804 2 ปีที่แล้ว

    Amazing!

  • @mahadifamgate2686
    @mahadifamgate2686 3 ปีที่แล้ว

    very nice things , a good chanel.

  • @saurabhpandey8174
    @saurabhpandey8174 2 ปีที่แล้ว +1

    Char *str is stored in .ro memory ☺️