Initializing an Array

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

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

  • @tiwaritejaswo
    @tiwaritejaswo 3 года назад +14

    Videos from Neso Academy are absolute gold. Pure concept.

  • @sahilanower9189
    @sahilanower9189 6 лет назад +54

    Great sir. Neso Academy's way of explanation is really exciting. Would love to see you get more views by people such as me❤

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

    5:00 int arr[10] = {}; works in 2023. The c complier may be updated. I tested this using both gcc and clang. Here is the test code : #include
    int main()
    {
    int a[10] = {};
    for ( int i = 0; i < 10; i++ ) printf("a[%d] = %d
    ", i, a[i]);
    return 0;
    }

  • @elaounisalman4028
    @elaounisalman4028 5 лет назад +14

    thank you so muuuuch from Germany Sir

  • @shankarbhandari3901
    @shankarbhandari3901 5 лет назад +5

    i m from nepal & its helping us a lot! thank you very much sir

  • @upgradojha
    @upgradojha 7 месяцев назад +1

    A small correct at 5:20 The statement `int arr[10] = {};` is legal in C, but its interpretation and behavior might not be immediately clear to all compilers, depending on the C standard they adhere to.
    Explanation:
    1. **C99 and later**:
    - In C99 and later standards, you can initialize an array with `{}`. This is called a "universal zero initializer". It means that all elements of the array will be initialized to zero.
    - The statement `int arr[10] = {};` will initialize all elements of `arr` to `0`.
    2. **Pre-C99**:
    - In C89/90 (the earlier C standard), the empty braces `{}` as an initializer might not be explicitly supported, and this could lead to a compiler error or warning.
    - Instead, you would typically initialize an array explicitly or with `{0}`:
    ```c
    int arr[10] = {0}; // All elements initialized to 0.
    ```
    Example in Code:
    ```c
    #include
    int main() {
    int arr[10] = {}; // Legal in C99 and later
    for(int i = 0; i < 10; i++) {
    printf("%d ", arr[i]);
    }
    return 0;
    }
    ```
    Compatibility:
    - If you are using a compiler that supports C99 or later, the code should compile and run without issues, initializing all elements to zero.
    - If using an older compiler that does not support C99, you may get an error or warning. In such cases, use `int arr[10] = {0};` for compatibility.
    ### Conclusion:
    - `int arr[10] = {};` is legal and initializes all elements to zero in C99 and later.
    - For maximum compatibility with older C standards, use `int arr[10] = {0};`.

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

    found this after my mid sem , hopefully ill ace my end sem by learning from this , hats off to u sir, ur infinite times better than my teacher !

  • @sumansahoo4433
    @sumansahoo4433 3 года назад +5

    Programming can't be more easier how you making this!❤️❤️❤️

  • @nexusbeing6403
    @nexusbeing6403 3 года назад

    Hey, at 3:45 the garbage value at first gives 0 for the length if it exceeds by 1 but if I use more memory for rest of the unspecified bits it gives/allocates some garbage value to the array.

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

    Sir u are a genius in explaining and this channel is great

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

    I m now doing my 1semister of my CSE the best explanation...that I have seen

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

    Thanku for ur clear voice and explanation sir

  • @samirgiripunje9202
    @samirgiripunje9202 3 года назад +1

    Sir at 3:40 my sir told that it store garbage value instead of 0's to save time and working 🙄
    Other please correct me🙏all who ever know this

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

    Great sir we are lucky to have a teacher like you ❤

  • @smp2221
    @smp2221 3 года назад

    Sahi insaan ko pakda maine ab c sikhne ke liye 🤗thank u soo much 💖

  • @ayonmitra4767
    @ayonmitra4767 6 лет назад +6

    Also please upload pointers, structures and data structure implementation in c(tree, stack, queue, link list, malloc etc..) Thank you

  • @ashishsinha8893
    @ashishsinha8893 6 лет назад +8

    Sir it's my heartiest request plz upload regularly my interview are near

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

      What are you doing now? Any job aur interview ka kya hua 😮

  • @naveedishtiaq938
    @naveedishtiaq938 4 года назад +1

    Write a program that initialize array of size 10, and prints all Armstrong and Palindrome numbers in array. Your program should ask user about their choice of printing. If user press ‘A’ or ‘a’ then program should display all Armstrong numbers in array and if user press ‘P’ or ‘p’ then it should display all Palindrome numbers in array.

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

    in the topic Initializing Array @5:17 to 5:25. you mentioned that you cant add more elements to an array than the specified size of the array. This happens to not be the case as C actually allows you to add more elements than the size array which of course could lead to a lot of problems but I think its worth noting as it appears to be a weakness with the c programming language

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

    Thanks a lot sir... I barely got any doubt in this topic now

  • @annakudriavtseva6660
    @annakudriavtseva6660 5 лет назад +2

    in method 1 and 2 how can you initialize array not at declaration?

  • @aryatamang5766
    @aryatamang5766 6 лет назад +2

    will you please provide the tutorials of Design analysis and algorithm?

  • @mugurukadanson8282
    @mugurukadanson8282 3 месяца назад +1

    why increment in method 4 in initialising a 1d array

  • @Salamanca-joro
    @Salamanca-joro 8 месяцев назад

    4:51 its not illegal it works actually it will be filled by value of zero

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

    You are excellent man, keep up the good work 👍👍

  • @kunalsoni7681
    @kunalsoni7681 5 лет назад +5

    sir that's truth.. sir you are genius on c programming.. sir your explanation is awesome for students.. 😊

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

      please checkout my channel i teach C in hindi with codes i make and i will make them in front of you not any presentation.

  • @bharathi1337
    @bharathi1337 4 года назад +1

    Perfect explaination 👌👌

  • @sanjayprabhushetty4309
    @sanjayprabhushetty4309 5 лет назад +4

    int a[5]={}; still initializes all array elements to zero why is this illegal?\

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

    Sir you are the best with your wonderful explaination and clear👍👍🤗

  • @luckyrawat5656
    @luckyrawat5656 4 года назад +1

    Doing great job brother 👍

  • @chinua2518
    @chinua2518 3 года назад +3

    Great lectures Sir, this is so detailed.
    Is it possible to declare a 1D array like so;
    int arr[] = {0};

    • @anubhavsur1441
      @anubhavsur1441 3 года назад

      yes of course it is a valid element. 0 is of data type int so it is a valid array arr[]

  • @prettyangel2530
    @prettyangel2530 3 года назад +1

    Thank you so so much sir😊👍

  • @mr.fabulous2368
    @mr.fabulous2368 2 месяца назад

    Sir if
    Int arr[5]={1,2};
    Then remaining three array position will be Zero
    What about memory stored it would be 20 bytes or 8 bytes

  • @sadiqabdulrahimzai4915
    @sadiqabdulrahimzai4915 5 лет назад +1

    Thanks teacher your very helpful ..

  • @foramtrivedi7648
    @foramtrivedi7648 3 года назад

    thank-you so much sir you help a lot of people by this video

  • @tails_the_god
    @tails_the_god 3 года назад

    thank you so much sir greetings from usa this is the exact quick answer i was looking for! :D

  • @23_rehanahassan7
    @23_rehanahassan7 3 года назад

    Very well explained.. Thank u

  • @Nicole-jw9jn
    @Nicole-jw9jn 4 года назад +1

    thank you so much i enjoy programming bc of you!!!

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

    if you write
    int arr[SIZE] = {0};
    Only the first element will get the value zero and the rest are filled automatically by the compiler, try changing 0 to 1 and see the difference

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

    Great sir❤

  • @shannukichatpatikhabrein7867
    @shannukichatpatikhabrein7867 6 лет назад +1

    Nice video sir.. If possible plz upload video fast

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

    Awesome content an d good explanation too..

  • @NarendraKumar-yr5ox
    @NarendraKumar-yr5ox 5 лет назад +1

    Thanks for the uploaded this video🙏

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

    Sir, first of all, thank you that you make such good videos for us free of cost, but sir, I have a request that along with understanding, please provide us notes to write in the exam, because i dont know how to write in the exam.

  • @kamransaif2929
    @kamransaif2929 3 года назад

    Very Helpfull Lecture

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

    can u give a example for this int arr[10]={0}; code

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

    1:33 In method 1 and 2, data type for array is not written. But is it possible to declare and initialize arrays separately like that ?

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

    int arr[10] = {}; is legal when compile by GCC

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

    Sir , by keeping array size empty we can store any number of values

  • @Dayhmian
    @Dayhmian 6 лет назад +1

    Nice, keep up the good work.

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

    You are good, sir, I am just smiling😁

  • @simasaha81
    @simasaha81 3 года назад +37

    Will cops invade my house if I add more elements than mentioned?

    • @hanmayujiro9491
      @hanmayujiro9491 Год назад +9

      Yes you are sentenced to watch 10 hour skibbidi toilet

    • @jonathan-gx9oc
      @jonathan-gx9oc 9 месяцев назад +1

      Due to your good behaviour you are now released

    • @jawad4823
      @jawad4823 Месяц назад

      Yes

  • @priyankabehera8288
    @priyankabehera8288 3 года назад +1

    ❤❤❤ from odisha

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

    How can i get numbers in a array string if the numbers are between spaces?
    Example:
    Array string = { "12 3 20"}

  • @shaikmohammed2444
    @shaikmohammed2444 5 лет назад +1

    Really it helps me a lot

  • @maheliahmed3013
    @maheliahmed3013 3 года назад

    Can you explain about global array? please

  • @meenakshis7798
    @meenakshis7798 3 года назад

    Can you make lectures on python and it’s data structures too

  • @parbatbudha1150
    @parbatbudha1150 6 лет назад +1

    Very nice sir

  • @omprakashnarsale1334
    @omprakashnarsale1334 3 года назад

    sir in 1st and 2nd method you didnt declare type of an array it is correct or not?

  • @sakshirathoree2908
    @sakshirathoree2908 4 года назад

    sir but when input is greater than the length of the array,it's workinf fine It's not showing any error

  • @sabahoudini
    @sabahoudini 4 года назад

    If I declare an array of type float and initialise the first value as 0.0f. Will the rest of the values also be initialised as 0.0f? Example: float array[5] = {0.0f}; The reason I ask is because I'm working with a microcontroller and calculations on a float value will be done with double precision and not single precision unless I specify 0.0f and I don't need the extra accuracy but need to save computation time.

  • @techys4335
    @techys4335 4 года назад

    verry verry nice video sir thanks.

  • @officegaming-23
    @officegaming-23 4 года назад

    Please explain the 4method of array please🙏🙏🙏🙏🙏

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

    How can we write if we want to initialise all elements of the array with a number other than zero

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

    Sir ur much better than my hod

  • @praveenkumarraghubharathi7045
    @praveenkumarraghubharathi7045 6 лет назад

    waiting for u r next videooo....if u fastly upload u r videos it will helpfull for those people who are now learn c...

  • @sheikhmohdarmaan1484
    @sheikhmohdarmaan1484 3 года назад

    what happens when we directly print an array.. please reply

  • @onnojogot9014
    @onnojogot9014 3 года назад

    Thanks a lot sir

  • @thamiesongxaka605
    @thamiesongxaka605 4 года назад +1

    hi! just came across this video while roaming around, am very interested in learning programming, and was looking for definition of an array, any advise where can I start ?

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

      maybe you can start with learning c language

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

    Thank you

  • @kiminotoriko6178
    @kiminotoriko6178 3 года назад

    How to initialize array of string?
    string arr[] = {a, b, c, d};
    I do this but it's error

  • @amansoni6152
    @amansoni6152 3 года назад

    Please Make Such Courses for C++ !!

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

      please checkout my channel i teach C in hindi with codes i make and i will make them in front of you not any presentation.

  • @parbatbudha1150
    @parbatbudha1150 6 лет назад

    How to use pointer aary in function ?please make video on it sir.

  • @ZafarIqbal-xs1pn
    @ZafarIqbal-xs1pn 4 года назад

    Sir what means by creating of array

  • @umakothalikar8907
    @umakothalikar8907 3 года назад

    You r just awsome!!🤯

  • @akshpreetsingh36
    @akshpreetsingh36 5 лет назад

    what if we add more values than the size of the array

  • @carloschen9791
    @carloschen9791 5 лет назад

    The automatic inicilization with value = 0, does it work only with global variables o with locals also?

  • @brokendreamz1140
    @brokendreamz1140 5 лет назад

    simple explanation👍

  • @madhiranagender6758
    @madhiranagender6758 3 года назад

    Why was rest of the elements are zero.is there any chance the rest of the elements becomes garbage values?

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

    The illegal cases that u explained are not illegal at all. They are working just fine

  • @abhikumar4332
    @abhikumar4332 5 лет назад

    Very useful for me.

  • @newariya8965
    @newariya8965 5 лет назад

    Very good dada,,,,,

  • @akshayrode3546
    @akshayrode3546 5 лет назад

    In method 2, there should be data type involved...

  • @gaurabchan2171
    @gaurabchan2171 4 года назад

    I am beginner. Sadly unable to find series of lectue

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

    What's index means

  • @kevalpatel1470
    @kevalpatel1470 5 лет назад

    Thanks sir

  • @true4189
    @true4189 4 года назад

    Thank u

  • @ganamcyanskamcna4317
    @ganamcyanskamcna4317 5 лет назад

    int arr[10]={0};
    int arr[10]={1};
    if all ten elements are 1,can i express the way above?

    • @anjaliverma7949
      @anjaliverma7949 4 года назад

      No 1 value will allocated to first block other will get 0 values

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

      @@anjaliverma7949 any way to initiate the array with -2 of size 1lack

  • @novelmania2319
    @novelmania2319 4 года назад

    Oh Man you are Great

  • @lukusasmartmtambo2743
    @lukusasmartmtambo2743 5 лет назад

    sir can you kindly add links to the source code

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

    arr[10]; will also make all elements zero;

  • @rohitkhetan278
    @rohitkhetan278 3 года назад +1

    1) int arr[5];
    arr[5]={1,2,3,4,5};
    Why is this code showing error?
    2) int ar[5]={};
    Sir, even this code works fine in VS code.....in fact, this is the easiest way to initialize an array with all zero.

    • @meowrbius
      @meowrbius 3 года назад

      We cannot initialize and declare arrays separately like that. U can do only if u are assigning one element at a time.
      Ex :
      int arr[5];
      arr[0] = 1;
      arr[1] = 2;
      arr[2] = 3;
      arr[3] = 4;
      arr[4] = 5;

    • @darshanjaviya4770
      @darshanjaviya4770 3 года назад

      @@meowrbius arr[5] means you are accessing the 5th index of arr array(actually not initialising the array), If you have already declared array then you have to use method-3,4 not 1, to declare, define and intialize you can do int arr[5] = {1 ,2, 3, 4, 5}

    • @meowrbius
      @meowrbius 3 года назад

      @@darshanjaviya4770 yea.
      And in the video, he is saying no need to write data type in method 1. That's wrong actually

    • @darshanjaviya4770
      @darshanjaviya4770 3 года назад

      @@meowrbius yes I also noted that

  • @souravray8891
    @souravray8891 5 лет назад

    I like this channel.. 👍👍👍

  • @venkatchenam6981
    @venkatchenam6981 6 лет назад

    nice sir

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

    How about that, is that legal?
    👇
    int arr[ ] = {0}

  • @muskaan1537
    @muskaan1537 4 года назад

    Good

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

    please make it fast

  • @teenarana3744
    @teenarana3744 5 лет назад

    Nice

  • @sapien9246
    @sapien9246 3 года назад

    How did Rony got placed in xyz company as a software engineer without even knowing that basic thing

  • @sonusambharwal8828
    @sonusambharwal8828 5 лет назад

    Gjb sir