2D Array Basics | C Programming Tutorial

Поділитися
Вставка
  • Опубліковано 14 жов 2024
  • A tutorial on the basics of using 2D arrays in C. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

КОМЕНТАРІ • 39

  • @noskov5
    @noskov5 Рік тому +5

    Hey Mate, You are the best! Love and respect to You, dear professor, from a regular ukrainian C fan. I wish I could be Your student at the university 😌

  • @naboulsikhalid7763
    @naboulsikhalid7763 Рік тому +4

    actually this is my field of work "Matrix", I work with finite elements analysis and I will implemented it this week in one of my Home Work. Thank you for your help

  • @gormarduck1658
    @gormarduck1658 7 місяців тому +1

    thank you so much for your tutorials

  • @theintelmedia9355
    @theintelmedia9355 3 роки тому +6

    Please how can I replace an int array with a different int array?

    • @PortfolioCourses
      @PortfolioCourses  3 роки тому +6

      Do you mean copy the elements of one int array into another into array? That would look something like this:
      int a[] = {1,2,3,4,5};
      int b[] = {0,0,0,0,0};
      for (int i = 0; i < 5; i++)
      b[i] = a[i];
      ^^ this would copy the elements of 'a' into 'b'. If this isn't what you mean let me know, I can try to help. :-)

    • @theintelmedia9355
      @theintelmedia9355 3 роки тому

      @@PortfolioCourses thanks

  • @steel_hat_pirates
    @steel_hat_pirates 2 місяці тому

    You are awesome buddy!!

  • @rafacastellano
    @rafacastellano 2 роки тому +2

    I have a question, if I have a 2d array how can I make it so that the first line and first row are all filled with the number 0? (basically I want any 'coordenate' with x or y = 0 to have the numeric value 0). This is the code I have for generating the matrix:
    #include
    #include
    #include
    #define MAX_LIMIT 1000
    int main (){
    int l, c;
    int i, j;
    int m, n;
    char str[MAX_LIMIT];
    int sum;
    int zero = 0;
    scanf(" %d %d", &l, &c); // scan number of lines and columns
    fflush(stdin);
    int **mat = (int **)malloc((l+1) * sizeof(int*));
    if (**mat == NULL)
    return;
    for(i = 0; i < l+1; i++) mat[i] = (int *)malloc((c+1) * sizeof(int));
    for(i=1; i

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому +1

      I’m not sure what you mean by “first line” and whether that is different from the “first row”. But a loop that takes a counter variable from 0 to the number of columns could be used to set the first row elements all to 0. :-)

  • @fifaham
    @fifaham Рік тому +1

    Nice - thank you.

  • @hasan-hr5kl
    @hasan-hr5kl Рік тому

    love the vids , was wondering can you make a video about an array of lists, (an array and each block of the array points at a list , and how to move through it ) thanks

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      Hopefully one day I can do a video like that Hassan! :-) I do have a Udemy course on Linked Lists, but I know this is something different in terms of a data structure.

    • @hasan-hr5kl
      @hasan-hr5kl Рік тому

      @@PortfolioCourses im in uni and just finished my exams i dont think im going to use C anymore so wondering if u have java course for next semester that i can follow .thanks

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      @@hasan-hr5kl One day I do want to have a Java course, but I'm not sure if it will be in time for next semester for you.

    • @hasan-hr5kl
      @hasan-hr5kl Рік тому

      @@PortfolioCourses thanks anyways.

  • @yogeshchauhan9401
    @yogeshchauhan9401 Рік тому +1

    How to take input in 2d char array in c ?

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      Do you want to store individual characters into a 2D array? Or do you want to store strings into a 2D array of chars, with one string stored per row of the 2D char array? I'm just asking because there is a difference between how we do each of those things. :-)
      This video shows how to read a file into an array of strings: ua-cam.com/video/X-1qodkHCHo/v-deo.html. Reading from user input would be similar but instead of a file we would read user input using a technique such as one of these: ua-cam.com/video/f8589Y9LHHg/v-deo.html.
      Maybe I can make videos on both of these topics, they are good ideas Yogesh. :-)

    • @yogeshchauhan9401
      @yogeshchauhan9401 Рік тому +1

      @@PortfolioCourses thanks for the response ya i was asking about storing strings in 2D array .

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      OK, I may be able to do a video on that actually. In the meantime, hopefully those links can give you some ideas. :-)

  • @ettajunior5087
    @ettajunior5087 Рік тому +1

    Amazing, please do that with a function 🙏

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      What would you like to see done with a function and 2D arrays exactly? :-) I'm just curious, maybe I can make a video on it.

    • @ettajunior5087
      @ettajunior5087 Рік тому

      @@PortfolioCourses just to see how a function can be used to display 2d array 🙏

    • @ettajunior5087
      @ettajunior5087 Рік тому

      Please how can I contact you so as to get advice and helps on c programming. I really appreciate your videos ❤️

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      @@ettajunior5087 OK I'll try to make a video on that, and maybe one on passing 2D arrays to functions.

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      @@ettajunior5087 I'm not able to do 1 on 1 tutoring at the moment due to time constraints, but I try to answer questions posted on these videos. 🙂

  • @ion4497
    @ion4497 2 роки тому

    great video tanks