Variable Modifiers − Auto & Extern

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024
  • Programming & Data Structures: Auto and extern variable modifiers in C programming.
    Topics discussed:
    1. Auto modifier.
    2. Extern modifier.
    3. Extern modifier examples.
    4. Procedure to create a project and different files within that project.
    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 #VariableModifiers

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

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

    When I will pass college and get a job I will donate to Neso academy from my first salary. Thank you for your priceless efforts.

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

      They don't need they have enough now..

    • @user-vp1gv4hp1o
      @user-vp1gv4hp1o 10 หลายเดือนก่อน

      good idea @@shashinegative9366

    • @tufandas9065
      @tufandas9065 10 หลายเดือนก่อน

      hi where are you from??

    • @opgamerz877
      @opgamerz877 3 หลายเดือนก่อน +1

      You'll forget bro

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

    i love these lessons. It explains everything that I need to know in coding.

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

    clear and straightforward, better than my professor

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

      And Wrong:
      1. auto is the opposite of register. Declaring a variable as auto, prevents compiler-optimisation to turn it into a register-variable. Typically you want register-variables in inner loop, but declare variables of the outer loop first, so delare the variables for the outer loop as auto.
      2. Global variables are not initialized to zero. If your system/compiler does that - nice - but the C-standards says there is garbage.

  • @nataliab.9725
    @nataliab.9725 2 ปีที่แล้ว +6

    I am so glad I found this channel, I have been struggling to learn C for 2 years and now I'm finally understanding it! Thank you so so much!

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

    I'm actually getting better in C and also in DSA with this course. ❣❤💛🧡

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

    such a clear explaination ...thats the reason i always loved neso academy

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

    honestly, this channel needs more and ultimate support. thank you, sir.

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

    I was taught C language just to pass exam in first year in my coaching, though college teachers came occasionally... Now, I came to this tutorial, I already did DE tutorials from Neso, amazed to know so many things, wished Neso had uploaded it earlier...

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

    what an amazing and smooth way of explaining, thank you so much for your effort

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

    These lessons are a cut above the typical tutorial fare, these go slightly deeper into the mechanics of the language and I very much appreciate that. 👍

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

    My exam is knocking at the door. Your lecture keeping me fight like a survivor. Thanks a lot, sir. All my respect for you. ♥

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

    use of uninitialized local variables leads to undefined behaviour. It depends on the compiler, in the visual studio community if we print the value of uninitialized variable it gives compile-time error while in GCC compiler it prints 0

  • @user-je3jj6fu7y
    @user-je3jj6fu7y 2 ปีที่แล้ว

    I'm the student from taiwan , this lesson help me a lot in learning c , Just keep going , you already change the way the cs student around the world how to study. Thank you !!!!

  • @MJ-dq8om
    @MJ-dq8om 4 ปีที่แล้ว +1

    at 1:43 , I haven't initialized a variable in main function and by printing that variable,it gave me as 0 but not a garbage value.

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

    Really good Explanations, god bless you!

  • @Official-tk3nc
    @Official-tk3nc 4 ปีที่แล้ว +18

    Guys they are providing everything for free and some idots dislikes these types of videos. I think they need mental treatment

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

      they are unaceademy employess

    • @Leo-qr1rq
      @Leo-qr1rq 3 ปีที่แล้ว

      Chill bro it's bot,which was programmed by TH-cam

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

      They probably got mad they couldn’t figure it out or something

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

    1:44 sir what is garbage value and how it is printed?

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

    Thank you so much for making this video. It was worth seeing this video 😀😃

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

    GCC didn't compile program with auto keyword. It throws error:two or more data types in declaration of 'var'. While, cl(MSVC) printed 0.

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

    sir I had tried to print output for an integer(not initialized) but instead of printing any random garbage value it prints 0 all the time. why so?

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

      was it global?

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

      same and it was not global

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

      @@riturajpathak1905varies according to machine properties

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

      @@riturajpathak1905 ya but it is unpredictible in latest version of gcc. see geeks for geeks

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

      it happened for me too

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

    Beautifully explained, thanks alot!

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

    Thank you very much. simple and crisp lecture.

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

    simply precise and clear. thank you so much !

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

    amazing thanks so much for these lessons.

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

    Thank you so much, I will never forget you.
    Thank you so much again and again. ☺️☺️☺️❤️❤️❤️❤️🙏

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

    sir extern int a; doesn't work in my code blocks what should I do?
    my main.c
    #include
    extern int a;
    int main()
    {
    printf("%d", a);
    return 0;
    }
    and my other.c
    int a = 56;

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

    Very clear description. Thank you very much!

  • @krut4rth
    @krut4rth 5 หลายเดือนก่อน

    @2:35 int var; // It is just declared, not defined..
    // definition is when you assign memory to it with = operator

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

    Excellent way of Teaching !!!

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

    helpful. Thanks NESO, I love you guys

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

    Very clear explanation Sir, thank you.

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

    You definitely deserve more subscribers!!🙌

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

    Thanks for sharing so many small small details , not only for this topic but all topics in all of your videos ...
    I do have one question here for extern
    What if we declare int a = something in two different files and try to refer in our main file using extern ..which one it will refer?

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

    These lectures are just costless

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

    Yes after paying on, you will have not too much better tutorial 👍👍👍👍

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

    I will just leave a comment for myself. Feel free to comment, thanks. Global variables are initialized to 0 by default. Extern is short for external. It declares the variable but no definition (though you can also define it), therefore no memory allocated to it. This is used when we want access a variable of the same name but located and defined in the nearest outer scope which can also include other files in the current workspace. It avoids redifinition or having to find another variable name for the same variable. Autos can't be declared multiple times, but externs can be. Declaration then definition. Initialize == define.

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

    Sir, in my computer auto variable does not give garbage values it also initializes with 0 as same as global variable.

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

    Thank you so much for making such videos. These are very helpful and easy to understand 😊😊

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

    Sir then What is the use of auto modifier ,if it doesn't change anything in program.

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

    At 8:41 on Video 14 (Variable Modifier - Static) you place a variable outside the scope of any function and specifically call it global. Thus it retains its value and should be accessible to main which is within a completely different file. If this is true then why the need for extern? It appears to me that you cannot compile when you delete the line extern within main here in this video which seems to suggest just the opposite of Video 14 which is to say that int a= 5; is NOT really global after all.

  • @dr.anubhavkumarprasad5765
    @dr.anubhavkumarprasad5765 4 ปีที่แล้ว +1

    extern int a=10;
    extern int a; //do not have this name variable in any other file
    Above code do not produce error. Multiple declaration is allowed which is ok, but second line is linking to variable in same scope ?

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

      Yes exactly. By writing extern int a=10; it means both declaration and definition

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

    when i keep the variable global and uninitialized, its showing compilation error and for local variable (not initialized) its showing 0 and not garbage value....why is that?

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

    Good video. But you are wrong about c giving garbage value to var which is declared but not defined under auto. I did it in an online compiler but it doesn't give any random value as you said garbage value. Please correct me if I am wrong.

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

    What I think is, the extern variable works like the complement set. 'A' complement is equal to universal set minus 'A' set.

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

    Short and to the point videos, finally I found the course I needed. Thank you so much for all your effort. _/\_

  • @MustafaKaradeniz-yy1cx
    @MustafaKaradeniz-yy1cx 3 หลายเดือนก่อน +2

    As a turkish student, Hand me over to the Indian educators.

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

    Good Explanation
    What if there are multiple files with int a declaration and defination and a single extern int a in main file?
    If memory is not provided to extern int a, so when does the exact value and memory for variable a is filled?

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

    your expletation is quite magnificent

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

    best course ever...i loved it

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

    at 9.52 even if we dont write extern in main then also it will print 9 as we have already defined the global variable then why to use extern.

  • @Atsushi549
    @Atsushi549 21 วันที่ผ่านมา

    9:41 , do we still need to use extern int for accessing global variable?

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

    Hi thanks for the lessons I appreciate it very much. However, I have a question.
    I tried not intializing my variable with int var; and also with auto int var; where both are actually the same in the local scope.
    The result I obtained was zero instead of indeterminate/random/garbage value. Why is that so?
    This means the int var; in local is the same as if I declare it globally since int var; in global is always zero.
    Thank you and hope to hear your explanation when you're free. Cheers!

    • @Daisy-xs9yb
      @Daisy-xs9yb 2 ปีที่แล้ว

      int var in local getting zero is not the same as int var in global because when you declare a global variable the initial or the default value is zero but a local variable stores a random number so if you get a local variable equal zero then it is just a coincidence maybe if u give local int var another time it will give a diff ans. hope it helps

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

    if you are a nerdy nerd like my self and you are using vim or emacs you can access the variable by compiling the two files, like this "gcc main.c other.c -o main". where main is the executable.

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

    Thank you very much. You are a genius. 👍👍🔝🔝

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

    Awesome tutorial to learn c programming

  • @Sabari-gd3fw
    @Sabari-gd3fw ปีที่แล้ว

    Hi sir, Thanks for this useful content. I have one query in this , at 10:03 you told if extern variable don't have definition in current file, it will go and search other files to retrieve the definition..my question here is which file it takes first to search the definition of this extern variable...because in your case you have created only one "other.c" file...but in reality there are lot of files will be there.If I am varying that extern variables in multiple files which file definition it will consider first?

  • @snitabongale7823
    @snitabongale7823 10 หลายเดือนก่อน

    Very helpful video

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

    Awesome explanation!!

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

    @7:28 -> external variable declared is a global variable for that file right? All the global variables are by default initialized to 0, isn't it? why don't it give the output as 0 and instead giving an error?

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

    Will these concepts of system level features be used in other programing language like python?????????

  • @ProProgrammer-ss4gb
    @ProProgrammer-ss4gb 4 หลายเดือนก่อน

    Are the notes of these lectures available somewhere...? And how can i access them...?

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

    Thanks neso academy

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

    Thank you for a wonderful video and a great explanation.

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

    Very nice video 🔥🔥

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

    Thanks for the great content.

  • @csharpdev-software-engineer
    @csharpdev-software-engineer 3 ปีที่แล้ว

    👍👍👍 thanks for good tutorial!

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

    Thanku you sir. 🙏🙏🙏🙏🙏🙏

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

    To be honest , this course is better than some paid course.

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

    Thank you ❤️

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

    Very good tutorial, tysm.

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

    Please anyone tell me,are these lectures are enogh for gate 22 ..please.

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

    Best one you can get😍

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

    some people gets that value is zero. Instead of any garbage value. because of it depends on what was stored at the location assigned to variable. Some compliers may also initialize it to zero

  • @hibmoshar6206
    @hibmoshar6206 5 หลายเดือนก่อน

    thanks alot

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

    Great one sir!

  • @agamgill9563
    @agamgill9563 6 ปีที่แล้ว

    informative lecture....thanx sr...

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

    amazing

  • @JE-SyedAteebShah
    @JE-SyedAteebShah 3 ปีที่แล้ว

    Does [extern int var] always need to be a global variable???????

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

    sir auto is not giving any garbage value? in my pc

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

    now, what is the pros of external keyword, if we can just include one file in another in order to access his declared globale variable instead of those geeky flashy gamic extern keyword?

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

    simply awesomeeeee.....

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

    If I define variable int a =3; inside some function say func() then , I write extern int a; in main() and printf ("%d",a);
    Whether it will show 3 or error.

  • @sharau.99
    @sharau.99 4 ปีที่แล้ว

    You are excellent !!!

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

    JUST AMAZING!!

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

    Nice explanation

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

    dear sir i try it what i notice is when i auto char auto float is value is expect 0 also unsigned int

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

    What compiler u have use sir...

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

    What if there are three file in project and all other 1,other 2 have the value of a ,then which value is assigned to a.?

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

      Linker throws error. Only one time definition allowed. Linker get confused while binding the modules.

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

      @@abhishekmazumdar2072 if she declares it to be static global variable, there will be internal linkage, hence no error

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

    At 10:23 in this video you just initialized the extern variable a in main.c file , but at that time in othre.c file has a commented variable definition what if i would remove out that comment and define the variable like " int a=9; " at that other.c file and also write " extern int a=10; "in main.c file so what it would give as an output? is it producing an error because of multiple definition of a single variable or it will going to give priority to that externed initialized variable and give output=10?? help me as soon as possible..

    • @Rajesh-xz5ws
      @Rajesh-xz5ws 4 ปีที่แล้ว

      Compile in compiler yaar...

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

    Excellent lecture

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

    For me 'auto int var' giving 0 as output, when I won't initialize var, is garbage value?

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

    what will happen if there are multiple files that have defined variable 'a'
    Which file's value of a will the compiler access?

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

    The output when i use var in form of global variable as well as in the scope gives the output as same as 0. What would be the reason behind it????????

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

    What happen if we define int a=5,int a=6,in two different other file .what will be the output for extern variable.?

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

      If you define them in both files as global variables,this will lead to name collision,you can compile both you c files in this case ,but when it comes to linking peiod,error happend.

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

      possible to compile all three files separatly. but when linking ,error will raise that " 'a' variable redeclared multiple times"

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

    what if we create more than 2 files like i created 3 files and declaring int a = 2 and int a = 3 , and then i write extern int a in my 1st file , so when i write printf(a) what will print?

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

    I tried testing
    #include
    int main()
    {
    auto int var;
    printf("%d", var);
    return 0;
    }
    but
    0
    will be the output always to me, kindly check if I ever happen to have errors

  • @shubhampawar.7776
    @shubhampawar.7776 3 ปีที่แล้ว

    Masterpiece

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

    When using another compiler (gpp in atom) it didn't work at all. Perhaps no linker?
    Undefined symbols for architecture x86_64:
    "_dd", referenced from:
    _main in main-f1adc3.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

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

    Thanks

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

    Hey, I m not initializing var value still it is printing 0 as garbage value though I m not using global variable, why?