Initializing an Array

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • C Programming: Initializing an Array in C Programming.
    Topics discussed:
    1) Initialization of one-dimensional array.
    2) What will happen if the number of elements is less than the length of the array?
    3) Different ways to initialize an array with all the elements as zero.
    C Programming Lectures: goo.gl/7Eh2SS
    Follow Neso Academy on Instagram: @nesoacademy(bit.ly/2XP63OE)
    Follow me on Instagram: @jaspreetedu(bit.ly/2YX26E5)
    Contribute: www.nesoacademy...
    Memberships: bit.ly/2U7YSPI
    Books: www.nesoacademy...
    Website ► www.nesoacademy...
    Forum ► forum.nesoacade...
    Facebook ► goo.gl/Nt0PmB
    Twitter ► / nesoacademy
    Music:
    Axol x Alex Skrindo - You [NCS Release]
    #CProgrammingByNeso #CProgramming #Arrays #ArrayInitialization #ArraysInc

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

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

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

    • @hanmayujiro9491
      @hanmayujiro9491 8 หลายเดือนก่อน +8

      Yes you are sentenced to watch 10 hour skibbidi toilet

    • @jonathan-gx9oc
      @jonathan-gx9oc 5 หลายเดือนก่อน

      Due to your good behaviour you are now released

  • @upgradojha
    @upgradojha 3 หลายเดือนก่อน +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};`.

  • @sumansahoo4433
    @sumansahoo4433 2 ปีที่แล้ว +5

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

  • @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 !

  • @charansuvvari
    @charansuvvari 5 หลายเดือนก่อน +1

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

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

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

  • @buragapuvenkataratnam2395
    @buragapuvenkataratnam2395 ปีที่แล้ว +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

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

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

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

    Thanks teacher your very helpful ..

  • @shannukichatpatikhabrein7867
    @shannukichatpatikhabrein7867 5 ปีที่แล้ว +1

    Nice video sir.. If possible plz upload video fast

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

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

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

    Perfect explaination 👌👌

  • @Nicole-jw9jn
    @Nicole-jw9jn 4 ปีที่แล้ว +1

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

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

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

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

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

  • @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

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

    Really it helps me a lot

  • @23_rehanahassan7
    @23_rehanahassan7 3 ปีที่แล้ว

    Very well explained.. Thank u

  • @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.

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

    Sir ur much better than my hod

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

    Thank you sir

  • @Dayhmian
    @Dayhmian 5 ปีที่แล้ว +1

    Nice, keep up the good work.

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

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

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

    Very Helpfull Lecture

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

    Awesome content an d good explanation too..

  • @parbatbudha1150
    @parbatbudha1150 5 ปีที่แล้ว

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

  • @thamiesongxaka605
    @thamiesongxaka605 3 ปีที่แล้ว +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

  • @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 ?

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

    You are good, sir, I am just smiling😁

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

    Thanks a lot sir

  • @ashishsinha8893
    @ashishsinha8893 5 ปีที่แล้ว

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

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

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

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

    verry verry nice video sir thanks.

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

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

  • @SanePius
    @SanePius 8 หลายเดือนก่อน

    What's index means

  • @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

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

    sir can you kindly add links to the source code

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

    Nice

  • @technicalpradhan2936
    @technicalpradhan2936 5 ปีที่แล้ว

    aap ka video achha hai but thoda smjhane ka style thik nhi hai

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

    10 Q

  • @sahilanower9189
    @sahilanower9189 5 ปีที่แล้ว +50

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

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

    thank you so muuuuch from Germany Sir

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

    Videos from Neso Academy are absolute gold. Pure concept.

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

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

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

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

  • @ayonmitra4767
    @ayonmitra4767 5 ปีที่แล้ว +6

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

  • @ashishsinha8893
    @ashishsinha8893 5 ปีที่แล้ว +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 😮

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

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

  • @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 2 ปีที่แล้ว

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

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

    please make it fast

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

    ❤❤❤ from odisha

  • @aryatamang5766
    @aryatamang5766 5 ปีที่แล้ว +2

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

  • @naveedishtiaq938
    @naveedishtiaq938 3 ปีที่แล้ว +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.

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

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

  • @opst1704
    @opst1704 5 ปีที่แล้ว +1

    flower brackets :'D 5:50

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

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

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

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

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

    Thank you so so much sir😊👍

  • @NarendraKumar-yr5ox
    @NarendraKumar-yr5ox 5 ปีที่แล้ว +1

    Thanks for the uploaded this video🙏

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

    Doing great job brother 👍

  • @parbatbudha1150
    @parbatbudha1150 5 ปีที่แล้ว +1

    Very nice sir

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

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

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

    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;
    }

  • @kunalsoni7681
    @kunalsoni7681 5 ปีที่แล้ว +5

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

    • @akwpython
      @akwpython 11 หลายเดือนก่อน

      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.

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

    Thank You Sir

  • @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

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

    Thank you

  • @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

  • @Salamanca-joro
    @Salamanca-joro 4 หลายเดือนก่อน

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

  • @officegaming-23
    @officegaming-23 4 ปีที่แล้ว

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

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

    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.

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

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

  • @praveenkumarraghubharathi7045
    @praveenkumarraghubharathi7045 5 ปีที่แล้ว

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

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

    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.

  • @KavyasriKinjarapu
    @KavyasriKinjarapu 3 หลายเดือนก่อน

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

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

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

  • @carloschen9791
    @carloschen9791 5 ปีที่แล้ว

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

  • @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

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

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

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

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

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

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

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

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

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

    I am beginner. Sadly unable to find series of lectue

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

    Can you explain about global array? please

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

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

  • @akshayrode3546
    @akshayrode3546 5 ปีที่แล้ว

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

  • @ZafarIqbal-xs1pn
    @ZafarIqbal-xs1pn 4 ปีที่แล้ว

    Sir what means by creating of array

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

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

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

    You r just awsome!!🤯

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

    illegal was funny .

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

    Oh Man you are Great

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

    simple explanation👍

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

    Very good dada,,,,,

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

    Very useful for me.

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

    Great sir❤

  • @sonusambharwal8828
    @sonusambharwal8828 5 ปีที่แล้ว

    Gjb sir

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

    Thank u

  • @kevalpatel1470
    @kevalpatel1470 5 ปีที่แล้ว

    Thanks sir