What does int argc, char* argv[] mean?

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024
  • In this tutorial I explain the meaning of the argc and argv variables that are often passed in the main function of a C or C++ program.
    Want to learn C++? I highly recommend this book amzn.to/1PftaSt
    Donate - bit.ly/17vCDFx
    STILL NEED MORE HELP?
    Connect one-on-one with a Programming Tutor. Click the link below:
    trk.justanswer...
    :)

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

  • @hass89
    @hass89 8 ปีที่แล้ว +379

    Argc is ARGument Count and and argv is ARGument Vector.

    • @felipemartin8255
      @felipemartin8255 7 ปีที่แล้ว +13

      And "Vector reffers to an array, not a C++ or Euclidean vector"
      See reference here:
      www.cplusplus.com/articles/DEN36Up4/
      Ps.: Although the name of the site be cpluplus.com, all the teachings contained there are compatible with C.

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

      Kingsman is KINGdom's MAN.

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

      is he managing directory by programming ?

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

      what are counts and vectors in C?

    • @Phantom-fi8sc
      @Phantom-fi8sc 3 ปีที่แล้ว +1

      @@hetaeramancer I tried to print the argv it shows the path of some designated file

  • @mikroelektro
    @mikroelektro 8 ปีที่แล้ว +61

    Never understood it until I saw you video 👌👍

  • @Rookwie
    @Rookwie ปีที่แล้ว +13

    I couldn't understand this for so long, I read some stack overflow, watched some tutorials, looked up some problems and nothing helped until I found this video, great explanation!! Feels way better to finally understand this

  • @mustafaadam9697
    @mustafaadam9697 8 ปีที่แล้ว +196

    You CAN declare a variable inside a for loop in C. Just use C99 or C11.

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

      @Artem Katerynych It's a standard that the compilers have to follow. it's not a version

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

      @Artem Katerynych Well technically we're both late.

    • @316monisbandey3
      @316monisbandey3 4 ปีที่แล้ว

      @@nicolareiman9687 yes

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

      @@nicolareiman9687 it is a version, if you define it to be "[a] particular form or variation of an earlier or original type" (American Heritage Dictionary, 5th Edition). It's not a version of a particular C implementation -- such as a compiler or standard library -- but it is a version of the C language.
      Edit: And I'm also a year late, lol.

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

      i was about to. To be honest i dont get why ppl dont use c99. I just dont get it. If anyone can explain i will apreciate it alot

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

    I want this guy to explain literally everything in my life

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

    Hey Paul, I'd like you to thank for putting your energy into making this tutorial. It was really enlightening and it made me comprehend the concept much better. Keep up the awesome job.

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

    This scared me in the past to start with c++, but it's actually such a simple concept.

  • @eatyourspinachtomperez8700
    @eatyourspinachtomperez8700 7 ปีที่แล้ว +13

    Thx Paul.
    I recall Jullian Assange saying, "commitment requires sacrifice, courage is contageous". (The latter meaning if you surround yourself w/ your peers, courage is contageous).
    This said, while learning to code, (we're ALWAYS students however), we forget previous lessons etc, the "commitment" part is, constantly reviewing what we may forget.
    This said, THANK YOU for your great work here on TH-cam.
    Cheers
    T

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

    You are literally the best my professor expected most of us to know c and it took me about 2 weeks on an assignment because i couldn't figure this out but bc of u i have been able to solve the task on the assignment. Thank u.

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

    I remember being so intimidated by this when I started learning C++. But then I learned that I didn't need it at all and I forgot about it completely.

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

      so do i have to learn this or what bro i am a cs student who are a completely beginner :)

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

      @@ibrahimozmen9668 unless you are building commandline applications for Linux or old terminal based systems, you don't need to worry about it.

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

      @@mistakenmeme thanks bro. I just wanted to learn how it works

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

    Awesome video! I'm brazilian and I want you to know that your video are healping people from all around the world! Thank you very much!

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

    This is the clearest explanation I have ever seen on this particular item !

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

    You are better at explaining than my actual teachers. +1 sub

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

      maybe you mean sub++ ( I know, I'm not funny)

  • @hoanghieu6389
    @hoanghieu6389 8 ปีที่แล้ว +31

    excellent explain.

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

    Man, you are amazing! You really know what you're doing. Please, don't stop!!!

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

    I have been searching so much for this, even my book doesn't explain what is this, thx a lot

  • @AZUBUIKETHANKGOD-wp2ri
    @AZUBUIKETHANKGOD-wp2ri ปีที่แล้ว +1

    Quite a lucid explanation. Thanks Paul for making such an awesome video. You've gained a subscriber.

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

    That's very simple by listening you. Love the away you explain think. Nice work

  • @s.spambot9095
    @s.spambot9095 2 ปีที่แล้ว

    OMFG I was reading about this for like 1 hours and couldn't understand shit, and you made it so clear!!! Thank you!!

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

    Very clear, concise, to the point, intelligible. Many thxs

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

    You actually can declare a variable in a for loop in C
    And, how did you use your atoi(). Is it a std function from a C library.
    Thanks for this video. You actually made effort to make this concept as simple as possible

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

      yes it is, from stdlib.h

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

      @@franchezke2351 yea, I found out. Thanks

  • @GodOfLemon
    @GodOfLemon 7 ปีที่แล้ว +11

    My friend, in C you can declare "int i=0" in the for loop. Wish you the best!

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

      Alexandru Dinu yes, but that variable would be deleted as soon as the for loop finishes!

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

      @@ledues3336 Can you please explain a bit more? or point to the right source? Because CS50 does the same as Alexandru mention above.

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

      ​@@ledues3336 Yes, this is the intent.

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

    Mindblowing! First I wondered what it was in Java, then in C# and now I finally got the answer in C++ :)

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

      it's actually C

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

      @@frogsam4228 it's identical in this case

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

      @@adamodimattia Idk tbh bcz I know nothing about c++
      but I'm sure that the format of main itself is different also the standard library is iostream right?
      so I guess they can't be identical right

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

      @@frogsam4228 it is, but also in C++ you can use everyting what is in C, all the C libs too

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

      @@adamodimattia ooh I didn't know that
      thanks a lot

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

    thanks, i sleep thru my last lecture, this clears a lot!

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

    Thank you, very clear and concise explanation.

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

    Thank you for your video! I'm French and it's super easy for me to understand everything. You took your time to be understandable and thank you so much for that!

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

    always provide notes to things you have spoken makes us understand better okay 👍
    thank u so much for your efforts
    love from india

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

    i always declare variables in for loops in c

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

    so clear and excellent explanation.
    Just to mention that the arguments must have a space or TAB between them and not a ; or ,

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

    Oh my god you are my hero!!! thank you so much bro... subscribed already

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

    I'm new in porgramming and this video show me for what is this argc and argv. But for what need argc to count his own call from the elter process?

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

    SO WELL-EXPLAIN that I just signed in to give you a thumb-up!!! Thank you for the clear explanation.

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

    If you are not already, you should be a teacher. This is insanely clear.

  • @Elliandr
    @Elliandr 7 ปีที่แล้ว

    You explained this way better than my teacher.

  • @6183134
    @6183134 9 ปีที่แล้ว

    (In C programming it is not necessary to put in a for loop the type of the value...) Very good tutorial!!

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

    Bro holy shit. I misunderstood arg c and argv when i first heard it. But god damn now i finally know how to use it. Thank you so much

  • @frostypawsgaming1338
    @frostypawsgaming1338 7 ปีที่แล้ว

    Cool, this confirmed my book seemed weird that it said this had to double check. good job.

  • @juliedurbin4465
    @juliedurbin4465 7 ปีที่แล้ว

    This video was so helpful with understanding my embedded systems homework. Your video really clears some things up. Thanks so much!

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

    No words to explain. !!! Thanks a lot!!!!!

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

    really helpful, although the if loop seems unnecessary. If the argc

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

    Explicitly explained! Thank you paul!

  • @VietCong467
    @VietCong467 7 ปีที่แล้ว

    Brilliant explanation, Paul! You just got yourself a new subscriber!

  •  3 ปีที่แล้ว

    Great explanation, most of the university professors can't explain this.

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

    Thank you for this excential explanation!!

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

    Paul, A nice clear intelligent presentation.
    Well done and thank you!
    (Props also to Hassanin Ahmed, below.)

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

    Thanks works fine. Greetings from Italy

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

    Well explained Paul. Thanks.

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

    BRAVO! Thanks so much sir.

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

    From ALX AFRICA
    Nice Explanation!

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

    Thanks for the explanation, God bless you!!!

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

    good one
    i can put scanf back on the shelf and just pass values in when i run stuff
    many thanks for sharing your knowledge
    subbed

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

    EXCELLENT video, just subscribed. thanks

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

    Did you make a C programming tutorial? You explanations are so clear

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

    You just got a new subscriber thanks Paul

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

    Main question remains unanswered, Why do we use outside run argument from command line, when we could easily get the same output by conventional way

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

      That is rather about personal wish, many programs are designed to check if argc ==0 if it is then manually ask for the inputs, it's for them who need their work done quick

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

      We use g++ something.cpp and we are also providing input at commandline rather than
      g++
      g++ : Enter name of file to be compiled - something.cpp
      We use it cuz some programs dont support manual input or personal wish

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

    Thanks, this has confused me and I have it on my exam. You cleared it up :)

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

    Thanks Paul for this insightful video 😊.

  • @kebsem
    @kebsem 8 ปีที่แล้ว

    Thank you very much. The video was clear, easy to understand, and helpful!

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

    finally the first helpful vid on this topic!

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

    perfect lecture!~thank you, Paul~~~~~

  • @TransparentOperatingMode
    @TransparentOperatingMode 9 หลายเดือนก่อน +1

    You say you can't use 'int' inside your declaration of a for loop: for (int i = 0; ;) Yet I've never had an issue with it in C. I do it all the time. No problems ever.

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

    Thank you. Your teaching had a very clear progression from basic code to more complex code.

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

    I learn something today! Good explanation. Thanks!

  • @AndrewChapman-j6p
    @AndrewChapman-j6p 7 หลายเดือนก่อน

    So clear and simple ❤

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

    excellent explanation.I've also seen some "cousins" of this. Can you tell me what is the difference between the following?int main(int argc, char* argv[])int main(int argc, char *argv[])int main(int argc, char** argv)int main( int argc, char **argv)

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

      This is very late, but I got recommended this video, so this is for anyone reading. Spaces don't matter when placing the asterisk in a pointer declaration.
      Also, technically, the C library passes a pointer to a pointer to main, hence the **argv. The array definition (with the brackets) is just syntactic sugar and makes it more understandable. You can test this by calling sizeof(argv). If it's actually an array, the size of the array would be stored on the stack, but it's actually just of type char**, so it'll return 8 on a 64-bit machine (which is the size of a pointer). The memory addresses to the strings are just stored one after the other.

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

      @@NateROCKS112 does that mean **argv and *argv[] both indicate pointer to pointer?

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

      @@DbCo0pEr yes. To my knowledge, in C, when you declare an array as a function parameter (e.g., void my_function(int my_array[]);), the array "decays" into a pointer. So it's purely syntactic sugar in that case. Edit: However, it can help to think of it as an array conceptually, and the type declaration still appears in documentation. I would personally use char *argv[] for that reason. Edit 2: I did want to note that normal arrays, such as within the same function scope, are slightly different from pointers, mostly in that sizeof actually gives the size of the array. So it's not just syntactic sugar in that case.

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

      @@NateROCKS112 You have to really know what you are doing . What the compiler sees and what you see aren't always a matchup , take obfuscated C for example , the compiler knows exactly what to do even though you may have no idea whatsoever by reading the code . That's why so many people are afraid of C !

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

    good explanation. well understood. thanks man

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

    Thank you, from Turkey.

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

    Bro, thanks for details explanation.

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

    thanks a lot!!! so nice reverb

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

    Thank you so much for the help!

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

    Thanks so much dude,it really helps me in terms of my final...

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

    Real savior!!!! Thank you!!!!

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

    Very good explenation!

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

    Thank you. Pretty decent explanation.

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

    Thanks for this tutorial!!! It helps a lot!

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

    Thanks it is very well explained

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

    Thanks to share!

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

    great explanation

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

    Very helpful
    Thanks a lot

    • @mostafaezz8208
      @mostafaezz8208 9 ปีที่แล้ว

      If you could make a video for pointer to function,
      it will great

  • @shashamnk2525
    @shashamnk2525 9 ปีที่แล้ว

    This is great! thanks from India paul

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

    great explanation
    understood in one go...

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

    Thanks for the explanation I get it, but why is it required? What happens in the background process?

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

    You are a Hero. Are there any video list about similar topics about visualization, linux and bash etc.

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

    Thanks super clear explanation !

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

    Really helpful, thanks!

  • @TurskoVideos
    @TurskoVideos 7 ปีที่แล้ว

    Wow makes so much sense now. Thank you!

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

    Well and clear explanationn...

  • @BittiKit
    @BittiKit 7 ปีที่แล้ว

    Thank you so much! Very clear explanation.

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

    thanks that was cool
    but I want to say that I'm sure that if you declare int i inside the initialisation part of the loop that'll work in C
    I do it everytime
    and for the "if condition" part
    I guess you already know but I want to say it 😅 there's no need for that condition at that level bcz the loop start from 1 and the condition is strictly smaller than argc so if the argc is smaller than 1 the loop won't start at first place

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

    nice, when i took intermediate programming last semester my instructor insisted we all knew how to use argv and argc lol. should be very helpful to newer programmers.

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

    Perfectly understood

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

    i don't how to thank you. Thaaaaaank yoooooooou soooooooo much

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

    Thank you for this video

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

    best video explaining this! thank you

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

    excellent examples and explanations cheers!

  • @RCBajafreak
    @RCBajafreak 9 ปีที่แล้ว

    Perfectly explained, thx a lot bro!

  • @default-126
    @default-126 6 ปีที่แล้ว

    You are just amazing bro, thank you so much, you helped me a lot!

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

    Great explanation, thanks.

  • @youzhen11
    @youzhen11 7 ปีที่แล้ว

    fantastic explanation!

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

    Thanks 👍👍👍👍