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
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.
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.
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.
@@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.
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
@@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
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!
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.
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
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
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
I need help with make file. Hove kan i use argc and argv so efter every argv i should be use enter and efter using of two enter should be start prgram ?
4 ปีที่แล้ว
Great explanation, most of the university professors can't explain this.
Still confused how that can Help me in c progamming Like WE have this in chapter 1 basics before the hello world Programm and i cant See why this should be before My "First" Programm
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)
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 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.
@@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 !
how would you do this with displaying different image files? like if i want a dog picture, then when i run the code again i want a mountain image from the command prompt
When I do ./add 3 6 8, it printf the file path with ./add, but the rest are normal. it wll say argv[0] = [filepath]./a argv[1] = 3 argv[2] = 6 argv[2] = 8
Talking about C programming, is it the same to define the inputs in the main variable than to define them later? For example, if you need to input 2 integers with some predefined values, would it be correct to just write: int main() and then initialize the two integers with the constant values you want?
int var_1; int var_2; int main(int argc, char** argv){ var_1 = 55; var_2 = 45; } Are you asking if this is possible? The answer is yes and you could use pointer in this case as well, but it wouldbe worth less in a way.
When running the program, how does argc know know many inputs there are? When you put three inputs, argc becomes 3. Does it read how many arguments there are and then count that for the "int argc"? If you were to do this in java, you'd write some code that would read the inputs from the user and count how many inputs there were. How does it do it in this case with C?
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
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
Argc is ARGument Count and and argv is ARGument Vector.
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.
Kingsman is KINGdom's MAN.
is he managing directory by programming ?
what are counts and vectors in C?
@@hetaeramancer I tried to print the argv it shows the path of some designated file
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.
Never understood it until I saw you video 👌👍
I want this guy to explain literally everything in my life
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.
You CAN declare a variable inside a for loop in C. Just use C99 or C11.
@Artem Katerynych It's a standard that the compilers have to follow. it's not a version
@Artem Katerynych Well technically we're both late.
@@nicolareiman9687 yes
@@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.
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
This scared me in the past to start with c++, but it's actually such a simple concept.
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!
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
This is the clearest explanation I have ever seen on this particular item !
You are better at explaining than my actual teachers. +1 sub
maybe you mean sub++ ( I know, I'm not funny)
I have been searching so much for this, even my book doesn't explain what is this, thx a lot
Man, you are amazing! You really know what you're doing. Please, don't stop!!!
Quite a lucid explanation. Thanks Paul for making such an awesome video. You've gained a subscriber.
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.
so do i have to learn this or what bro i am a cs student who are a completely beginner :)
@@ibrahimozmen9668 unless you are building commandline applications for Linux or old terminal based systems, you don't need to worry about it.
@@mistakenmeme thanks bro. I just wanted to learn how it works
OMFG I was reading about this for like 1 hours and couldn't understand shit, and you made it so clear!!! Thank you!!
Mindblowing! First I wondered what it was in Java, then in C# and now I finally got the answer in C++ :)
it's actually C
@@frogsam4228 it's identical in this case
@@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
@@frogsam4228 it is, but also in C++ you can use everyting what is in C, all the C libs too
@@adamodimattia ooh I didn't know that
thanks a lot
Very clear, concise, to the point, intelligible. Many thxs
That's very simple by listening you. Love the away you explain think. Nice work
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!
SO WELL-EXPLAIN that I just signed in to give you a thumb-up!!! Thank you for the clear explanation.
always provide notes to things you have spoken makes us understand better okay 👍
thank u so much for your efforts
love from india
Brilliant explanation, Paul! You just got yourself a new subscriber!
thanks, i sleep thru my last lecture, this clears a lot!
excellent explain.
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.
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?
This video was so helpful with understanding my embedded systems homework. Your video really clears some things up. Thanks so much!
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
yes it is, from stdlib.h
@@franchezke2351 yea, I found out. Thanks
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
i always declare variables in for loops in c
Oh my god you are my hero!!! thank you so much bro... subscribed already
so clear and excellent explanation.
Just to mention that the arguments must have a space or TAB between them and not a ; or ,
Paul, A nice clear intelligent presentation.
Well done and thank you!
(Props also to Hassanin Ahmed, below.)
finally the first helpful vid on this topic!
thanks for the video . i have a question while initiating i in the for loop why do we need to include i
You explained this way better than my teacher.
My friend, in C you can declare "int i=0" in the for loop. Wish you the best!
Alexandru Dinu yes, but that variable would be deleted as soon as the for loop finishes!
@@ledues3336 Can you please explain a bit more? or point to the right source? Because CS50 does the same as Alexandru mention above.
@@ledues3336 Yes, this is the intent.
Thank you, very clear and concise explanation.
(In C programming it is not necessary to put in a for loop the type of the value...) Very good tutorial!!
really helpful, although the if loop seems unnecessary. If the argc
Thanks, this has confused me and I have it on my exam. You cleared it up :)
Cool, this confirmed my book seemed weird that it said this had to double check. good job.
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
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
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
I need help with make file. Hove kan i use argc and argv so efter every argv i should be use enter and efter using of two enter should be start prgram ?
Great explanation, most of the university professors can't explain this.
right... but how to do the same in the comand line in windows?
tnks in advance
Still confused how that can Help me in c progamming Like WE have this in chapter 1 basics before the hello world Programm and i cant See why this should be before My "First" Programm
Explicitly explained! Thank you paul!
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)
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.
@@NateROCKS112 does that mean **argv and *argv[] both indicate pointer to pointer?
@@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.
@@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 !
how did you get your program to run in the bash or command prompt? I created/ran it with console app and I can't write ./add 3 2 5 or anything to it.
Did you make a C programming tutorial? You explanations are so clear
No words to explain. !!! Thanks a lot!!!!!
How do you even get the window in the rightside? As a begginer I have no idea what that is.
He's using the terminal on Mac OS.
how would you do this with displaying different image files? like if i want a dog picture, then when i run the code again i want a mountain image from the command prompt
When I do ./add 3 6 8, it printf the file path with ./add, but the rest are normal. it wll say argv[0] = [filepath]./a argv[1] = 3 argv[2] = 6 argv[2] = 8
Thanks for the explanation I get it, but why is it required? What happens in the background process?
If you are not already, you should be a teacher. This is insanely clear.
How would you test by attempting to open the file and checking to see if the open was successful?
How did you get the ARGS file, that's the part that I don't understand.
You just got a new subscriber thanks Paul
Hai did you end up made another video of what happened when the user input is not an int?
I have one doudt sir?why argv take the char data type and then u convert to the integer is their any reason
From ALX AFRICA
Nice Explanation!
Thanks Paul for this insightful video 😊.
To use echo do you type ./echo ?
BRAVO! Thanks so much sir.
Well explained Paul. Thanks.
Thanks works fine. Greetings from Italy
How to print error message if we take inputs other than integers like char, float
use exceptions
Thank you very much. The video was clear, easy to understand, and helpful!
how can i print all the arguments without using argc
Thank you for this excential explanation!!
Talking about C programming, is it the same to define the inputs in the main variable than to define them later? For example, if you need to input 2 integers with some predefined values, would it be correct to just write:
int main()
and then initialize the two integers with the constant values you want?
int var_1;
int var_2;
int main(int argc, char** argv){
var_1 = 55;
var_2 = 45;
}
Are you asking if this is possible? The answer is yes and you could use pointer in this case as well, but it wouldbe worth less in a way.
You are a Hero. Are there any video list about similar topics about visualization, linux and bash etc.
Sir which IDE use in this program
I learn something today! Good explanation. Thanks!
When running the program, how does argc know know many inputs there are?
When you put three inputs, argc becomes 3. Does it read how many arguments there are and then count that for the "int argc"?
If you were to do this in java, you'd write some code that would read the inputs from the user and count how many inputs there were.
How does it do it in this case with C?
read the source code ?
EXCELLENT video, just subscribed. thanks
perfect lecture!~thank you, Paul~~~~~
Thanks for this tutorial!!! It helps a lot!
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
What would happen if you write words between 3 and 2 and 5?
but how would it affect to the program?
what text editor are you using
This is great! thanks from India paul
Great video!
Just wanted to deepen my understanding, when will we want to use these?
Presumably when you want a quick way to pass in arguments into your program?
good explanation. well understood. thanks man
Thanks for your video.May I know if I use c++,could I use string[] instead.of char* []?
how to do this in windows ms plz reply
why doesn't argc start counting at 0?
Perfectly explained, thx a lot bro!
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
The for loop starts from i = 1. So how is the argv[0] printed?
you blind bruh !? for loop starts from 0.
hey brother argv[0] is not printed, we take argv indexes 1,2 and 3 only, argv[0] by default contains the name of your file.
Thanks for the explanation, God bless you!!!
Thank you. Your teaching had a very clear progression from basic code to more complex code.
Thanks so much dude,it really helps me in terms of my final...
any vids on a while loop in a while loop?
So clear and simple ❤
What is -o😂
@@AndrewChapman-j6pum... "Output" maybe?