C Programming Tutorial 83 - Printing Array with Loop

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ย. 2024

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

  • @Theodore2303
    @Theodore2303 4 ปีที่แล้ว +36

    I love your sense of humour. I don't just appreciate how you make programming so easy, but I also appreciate your personality (:

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

    Going through The C Programming Language book right now and got confused about the "Arrays" section, so I came here. I am super glad I found this explanation, thank you!!

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

    I am not sure if you cover it but you can also use sizeof to determine the length of the array.
    Instead of setting a variable size to a hard coded value. You can do:
    #include
    #include
    int main() {
    int arr[5] = {1,2,3,4,5};
    for (int i = 0; i < sizeof(arr)/sizeof(int); i++) {
    printf("
    %d", arr[i]);
    }
    return EXIT_SUCCESS;
    }
    What is your thought on using sizeof() to determine the length of arrays. I have read articles of conflicting opinions. Some say you shouldnt use sizeof(), others say use it.

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

      whatever works, works

  • @eyyubaydin1370
    @eyyubaydin1370 4 ปีที่แล้ว +4

    I am so happy that I am still watching this. Thanks for your work! It's simple for us to look and listen! Thanks

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

    I dont often judge people, but you are a hell of a nice guy

  • @tiagodmota5840
    @tiagodmota5840 4 ปีที่แล้ว

    #include
    int main(void)
    {
    int size = 3;
    int array[size];
    int i = 0;
    array[0] = 88;
    array[1] = 77;
    array[2] = 55;
    while(i < size)
    {
    printf("%d ", array[i++]);
    }
    return 0;
    }
    #WhileIsClean

    • @tiagodmota5840
      @tiagodmota5840 4 ปีที่แล้ว

      You can read the array as well:
      for(i = 0; i < size; i++)
      {
      printf("Array element %d: ", i);
      scanf("%d", &array[i]);
      }
      for(i = 0; i < size; i++)
      {
      printf("%d ", array[i]);
      }

  • @Hespiota
    @Hespiota 4 ปีที่แล้ว +1

    The dog is the real antagonist here.

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

    5:48 What did your dog want?

  • @foxTechAcademy-b7z
    @foxTechAcademy-b7z 3 ปีที่แล้ว +2

    You're amazing buddy, many thanks

  • @TheKsiksa
    @TheKsiksa 4 ปีที่แล้ว +4

    instead of having the size statically defined can you have it defined by user input: ???
    scanf("%d", &size);
    arr[size];
    (I tried this but returns seg fault 11)

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

      int a;
      scanf("%d", &a);
      int array[a];
      here it works, if you paste the code we can help '-'

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

      is it possible?? i mean you have to put the content in the arrays too man

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

      @@surjeetsingh3603 you could have user input "a" number of values

  • @johncardenas1843
    @johncardenas1843 ปีที่แล้ว

    Printing array is a array printer it changes thing in box u have to put in a
    Box your collection if was DVD watever

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

    i love this fam! this is good stuff.

  • @dinukakumara1113
    @dinukakumara1113 4 ปีที่แล้ว

    I have a question.If the array is myGrades and the size is 5.What happens when we didn't put myGrades[2]

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

    Followed this perfectly and carefully reviewed it and it still returns nothing when I compile. CS is hell.

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

    why does: int myGrades[size];
    word size has a red squiggly line under it? everything is correct based off your code.

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

      im using microsoft VS

  • @TheAutumn90
    @TheAutumn90 ปีที่แล้ว

    @2:55 My man said "all [uhh] all we have to do is.."

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

    Thank u!!! I love your personality too :D

  • @tiagodmota5840
    @tiagodmota5840 4 ปีที่แล้ว +1

    I tested and myGrades[ ] is 0 based.

  • @twilight_mourner1865
    @twilight_mourner1865 4 ปีที่แล้ว +1

    so I tried it but when I plugged the variable in here
    int size = 5;
    int myGrades[size];
    it says that it cannot have size as its array size and must be a constant value
    help?

    • @chrisgmag22
      @chrisgmag22 4 ปีที่แล้ว +1

      TRYHARD Gamer declare it as const int size = 5;
      Sizes are not supposed to chance, so you have yo change it to a constant value that way or with #define SIZE 5 right below your libraries

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

      @@chrisgmag22 if you #define size 5, you have to delete the int size = 5;
      God, intro to C is so annoying

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

    Line13 has a major flaw in it and the "for" statement never gets past " i++ ". I changed it to a "while" statement and put the " i ++ " below the "printf " and it works fine.

  • @Hespiota
    @Hespiota 4 ปีที่แล้ว +1

    Thank you!

  • @kenthsaya-ang3718
    @kenthsaya-ang3718 4 ปีที่แล้ว +1

    Is there something similar to array.length for C?

    • @niklasfrohnecke8720
      @niklasfrohnecke8720 4 ปีที่แล้ว

      According to Calebs c++ course, arrays don't know there own size. but there's a workaround for it: the "sizeof" function. it returns sizeof something bytewise. so to get the actual size of an array you need to divide sizeof(array) by sizeof(one element of that array). in code it would look smth like:
      int array[n];
      int size = sizeof(array) / sizeof(array[0]); // = n

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

    go for loops whoo! lol

  • @sallauddin1
    @sallauddin1 4 ปีที่แล้ว +1

    Thank you so much

  • @londonsystem6622
    @londonsystem6622 4 ปีที่แล้ว +1

    The best!

  • @dianne336
    @dianne336 4 ปีที่แล้ว +1

    Hello. What compiler do you use?

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

    whats the song at the end?

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

      Tropical Summer by ARTISS.
      www.jamendo.com/track/1452505/tropical-summer?language=en

  • @ragnarloothbrook6510
    @ragnarloothbrook6510 4 ปีที่แล้ว +1

    Nice

  • @aryan9088
    @aryan9088 4 ปีที่แล้ว +2

    ni yabba

  • @shubh-kr
    @shubh-kr 4 ปีที่แล้ว +1

    You are declaring a int at line 13 which isn't allowed in C.

    • @Gataroes
      @Gataroes 4 ปีที่แล้ว +2

      It's okay to declare a variable in a for loop. It just cannot be used outside of the loop.

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

    Thank you so much