C++ Tutorial - 25 - Passing Arrays into Functions

  Рет қаралды 128,043

thenewboston

thenewboston

Күн бұрын

Source Code: github.com/the...
Core Deployment Guide (AWS): docs.google.co...

Пікірлер: 134
@dmdrummer23
@dmdrummer23 14 жыл бұрын
@Molbs100 I regret not learning programming languages when i was younger. I didn't know anything about it until my 1st year engineering class, now I'm hooked haha. Good luck with the rest of C++.
@SimpleCookiee
@SimpleCookiee 12 жыл бұрын
I told my GF bucky seems very smart, when he talks he explain everything in a way like he really thought it through already on how to explain it and even the more advanced stuff he knows like what the particular libraries does. I also think he's clever. Cuz he knows many programming languages and he done a tutorial on how to make our own gokart
@pandachels5952
@pandachels5952 11 жыл бұрын
Just wanna say THANK YOU, since you really saved my life for midterm :)
@asfadasfa1234
@asfadasfa1234 14 жыл бұрын
@daeheadshot int num was a paramater in the answer function. what he did with it was used it as maximum amount of times the for loop could run. he said for(int i=0; i
@CraayC
@CraayC 13 жыл бұрын
The confusing thing for me was that he went from bottom to top to middle. Though I recommend people to watch all of it once, then watch all of it again while pausing the video whenever they're confused about something. He does actually explain everything he does - so just pause/replay a lot! Just remembert that "Bucky[]" is the Array ("Numbers") and "num" is the 5 different numbers/variables in the array.
@JesusTwoThousand
@JesusTwoThousand 11 жыл бұрын
Thanks, I passed all of them quite some time ago, and am currently as a programmer. To learn the basics, I never even needed a 30$ book, documentation sufficed.
@sidrocksinthisworld
@sidrocksinthisworld 12 жыл бұрын
what BS? this guy is pretty good you know? i learnt everything from a freaking book and didn't get half the things explained in there. he's pretty good at explaining all the concepts of c++ without overwhelming the viewer. give him some credit, wont you?
@BieberFever4evaar
@BieberFever4evaar 12 жыл бұрын
this saved my ass. i have an exam tomorow. thanks !
@ValosTaonas
@ValosTaonas 14 жыл бұрын
This is really cool and fun and it IS getting hard. After reviewing the file I made while following this tutorial, I'm still a bit confused but I'm sure I'll get it as I keep learning.
@ddoodm
@ddoodm 15 жыл бұрын
Yes! Finally another Cpp tutorial!!! :D Thanks Bucky! You rock!!!
@nitin1518
@nitin1518 14 жыл бұрын
@hamadrehman: fstream is used to operate on the file you will be using to read and write. cstlib C Standard General Utilities Library This header defines several general purpose functions, including dynamic memory management, random number generation, communication with the environment, integer arithmetic, searching, sorting and converting.
@dmdrummer23
@dmdrummer23 14 жыл бұрын
@Molbs100 I felt the same way in some of my C++ classes, but it will eventually click and make perfect sense. And it is really hard to teach something like programming once you understand it (like trying to tell someone how to drive a standard car). It all seems easy to him now, so it's hard to tell what people will have trouble with. I'd be glad to help with any specific questions (and bucky has a forum too).
@TheWhizzkiduk
@TheWhizzkiduk 15 жыл бұрын
I agree, everything was so clearly explained on the previous videos but as these progressed its way to fast, i keep having to stop it and reference stuff on websites, no problem though, when i do eventually understand it'll be good to come back and see it action
@bondservant4Him
@bondservant4Him 12 жыл бұрын
You dont need to return an array. The array is passed by reference so the changes reflect back to main, therefore there is no need to return an array :)
@fuel-pcbox
@fuel-pcbox 15 жыл бұрын
Interesting! Keep it up, dude!
@krepost3319
@krepost3319 15 жыл бұрын
Спасибо за работу! Так держать! Thanks )
@FtaAl3rab
@FtaAl3rab 13 жыл бұрын
Thank you dude your tutorials are very helpfull I'm following all of them and wonder where i was from them ..... i dont know why most comments are saying that u are fast ..???
@indianop45
@indianop45 14 жыл бұрын
really man....you seriously rock........gr8 work....
@emilgardis
@emilgardis 12 жыл бұрын
Awesome video bucky!
@Aggregate02
@Aggregate02 15 жыл бұрын
The function that you can try using is: sizeof() This works in C++ as well as C.
@krissi0013
@krissi0013 15 жыл бұрын
For those who are having trouble grasping this, try back tracing from the final results. the "total"
@bondservant4Him
@bondservant4Him 12 жыл бұрын
If you pass an array to a function and you make changes to that array in the function. Then when the function is finished your array in main will be changed. So therefore there is really no need to return an array.
@devengovender101
@devengovender101 11 жыл бұрын
It takes all the elements in the array numbers[] which is actually passed on as bucky[] and adds all the elements and store it as sum.
@shiinondogewalker1675
@shiinondogewalker1675 12 жыл бұрын
Yes! but you will need fast fingers to do all calculations needed in a game or something ^^
@dmdrummer23
@dmdrummer23 14 жыл бұрын
@acollsen i would say learn C++/C (and maybe Java too) first, and then you will learn other languages much faster. There is no 'best' language, it depends on preference and application. I think C++ is more difficult, but very efficient and good for games.
@varan9595
@varan9595 12 жыл бұрын
"make sure you have a couple of typos in there" lmao
@MortazaHussein
@MortazaHussein 12 жыл бұрын
thank you very much , it helps me well
@hewgouw
@hewgouw 14 жыл бұрын
@johnnyc130 no, "int numbers[5]" have 5 elements, 0, 1, 2, 3 and 4
@acollsen
@acollsen 14 жыл бұрын
A question. People say that C++ is the best language. But I want to know why. I have a hard time choosing what language to learn more about. I tried this in both Python and in C++ and python seems more easy to understand. What is good and what is bad with C++ and Python? Please respond. Here is my code for this in Python: arr = [13, 45, 3, 765, 44] def Calc(array): summa = 0 for i in array: summa += i return summa print "The sum of the array is:", Calc(arr)
@audiocorps2334
@audiocorps2334 12 жыл бұрын
My professor is really against the use of ++, --, +=, -=, /=, etc. Said this was during the time where we had less memory... Is it really a bad idea to use these, or just the incre/decre-mentals? It seems more convenient and less cluttering if I just used those...
@chendo2299
@chendo2299 14 жыл бұрын
First one i had to actually go over to fully understand lol
@DzahierulAliemy
@DzahierulAliemy 4 жыл бұрын
Thank you very much sir.
@MattCoffey6933
@MattCoffey6933 12 жыл бұрын
When I run the program(after I compiled it) it gives me this error: "Segmentation fault (core dumped) " any ideas?
@manishsakariya4595
@manishsakariya4595 11 жыл бұрын
nice bro... keep it up....
@bondservant4Him
@bondservant4Him 13 жыл бұрын
@Pradipna so doesnt that mean the array is always passed by reference?
@bundeligafan
@bundeligafan 14 жыл бұрын
we can simply say cout
@Aggregate02
@Aggregate02 15 жыл бұрын
Yeah, but you can create a simple function using the sizeof() function and divide it by the size of the variable type.
@bondservant4Him
@bondservant4Him 12 жыл бұрын
an array is already a pointer to the first element. It can be confusing, I find the best way to understand it is to do some practice code and see what works and what doesnt then it will become more obvious to you. If you have any code you have questions on, PM me it and ill try and explain my best.
@dominicjan
@dominicjan 14 жыл бұрын
i did'nt get the "int i" part but it appears its allowed to declare variables in the loop. also i forgot how the FOR loop works - had to revise that. the ride is getting bumpier and bumpier.
@Ubokhalid
@Ubokhalid 11 жыл бұрын
aray
@leviterande
@leviterande 15 жыл бұрын
Hi I have one question and I am in college. the I am in course supposes to be for total newbie beginners in C. my question is, is it normal to already after 3 weeks from the start we are studying adding matrixes and arrays together in other functions.. we have covered too many things and we took loops the second week...
@JesusTwoThousand
@JesusTwoThousand 12 жыл бұрын
Because I wish you well.
@bondservant4Him
@bondservant4Him 13 жыл бұрын
@Pradipna so why would anyone pass a pointer to the array if its already a pointer, is there a reason?
@h434421
@h434421 12 жыл бұрын
Im confused about something, when he made the array big enough for 5 integers. I thought that it actually started at 0 so wouldn't it actually be big enough for 6 integers?
@kasper3442
@kasper3442 11 жыл бұрын
You need to input an array as you've declared in the body of your function.
@alberthuynh
@alberthuynh 12 жыл бұрын
bucky always say he will get a bunch of errors but never does lol
@Jamiewinters8
@Jamiewinters8 11 жыл бұрын
could you type int total=answer({4,5,6,7,8},5); ? or do you need to do something special to enter an array without setting it to a variable?
@04azey
@04azey 13 жыл бұрын
How can i write a C application that allows users to perform 2 basic Matrix operations in the form of functions
@FrankLopezx
@FrankLopezx 9 жыл бұрын
im not sure but i dont think bucky should off teach this backwards? start on the top and work your way to the bottom of the loop, cuz when he starts in loop and work his was up i get lost as im still trying to understand the logic behind passing a function with variables not mentioned yet as they are part of a int main() and then im thinking how do i pass this in a setup() in Arduino and i get lost
@lvj8519
@lvj8519 9 жыл бұрын
Question: instead of "int total=answer(numbers, 5);" ..... re: 2nd line in the main function, I used (numbers,1), and it showed the number four (4). It appears that the rule that arrays start with the number zero(0) does not apply in this case, and such rule is merely a general rule with exceptions?
@crateer
@crateer 6 жыл бұрын
Wrong.
@SimpleCookiee
@SimpleCookiee 12 жыл бұрын
Figured it out already
@talkingfractal
@talkingfractal 15 жыл бұрын
Is there something similar to python for c++ when checking for the length of an list/array ? python: len(list) c++: ???
@GianLazaro93
@GianLazaro93 11 жыл бұрын
Since C++ converts any arrays passed to a function a pointer, why not just use pointers as arguments?
@kurmakk
@kurmakk 14 жыл бұрын
@coolguyace took me a couple reviews of previous vids to understand this one....least i kno i wasnt alone in not understanding!
@HarshPrriyaOfficial
@HarshPrriyaOfficial 13 жыл бұрын
Can we also pass the reference of an array into a function?
@Desiqnify
@Desiqnify 7 жыл бұрын
what if you want to return an array pointer? How would you call that to the method?
@FrankLopezx
@FrankLopezx 9 жыл бұрын
this is nice and all but how do you pass this functions over wireless in another platform? "Arduino"
@SimpleCookiee
@SimpleCookiee 12 жыл бұрын
Btw.. I don't understand the purpose of the variable "num" in this video.. It doesn't make much sense to me. Could someone explain to me it's purpose? How it works
@HawxTeamDelta
@HawxTeamDelta 14 жыл бұрын
hey bucky why you didnt remove the name of your parameter in the prototype you made? that made me confuse although i think i get it but it'll be more better for me if i get an explanation for that..
@shapbrain
@shapbrain 13 жыл бұрын
Bucky, can u please solve the following problem using c++ 1)Write a function that accepts an array of non-negative integers and returns the second largest integer in the array. Return -1 if there is no second largest. You may assume that the input array has no negative values in it. Thanks in advance :D
@chernobila
@chernobila 15 жыл бұрын
hello sir are you going to post more C++ tutorials? Please do Thank you
@jezzie7354
@jezzie7354 11 жыл бұрын
u rock!
@jakobskof
@jakobskof 13 жыл бұрын
i have gat a problem ISO C++ forbids comparison between pointer and integer i dont now why
@LPSlasher
@LPSlasher 14 жыл бұрын
BE AWARE! (lol) If you try this and somehow it gives you a number with comma or in any way NOT an ENTIRE number, you'll have to use 'double' instead of 'int' (int stands for entire numbers ONLY, double stands for both)
@danfebra1016
@danfebra1016 10 жыл бұрын
i just want to ask in the line int total=answer(number,5) is the number the name of the array? and 5 are the numbers inside the array?
@AsakuraClan
@AsakuraClan 10 жыл бұрын
yes that is exactly what is it. atleast to my understanding.
@TheGoldenChildJai
@TheGoldenChildJai 14 жыл бұрын
what if the input parameter are doubles how would you do that?
@nashs8979
@nashs8979 10 жыл бұрын
HI wanted to ask can we pass a multidimensional array in the same way?
@hrbharry
@hrbharry 11 жыл бұрын
'number+=5' would be equal to 'number = number + 5'
@mjdhiru
@mjdhiru 13 жыл бұрын
@Programmer40 thank u so much :DD
@talkingfractal
@talkingfractal 15 жыл бұрын
Thank you
@norgen4
@norgen4 5 жыл бұрын
Ur the goat come back
@mjdhiru
@mjdhiru 13 жыл бұрын
@Programmer40 ok thanks... i got another doubt.... if u know everything about c++....can u go to buckys c++ tutorial video series and see the 49th video...i commented a post on that...can u plz help me wid dat..
@mjdhiru
@mjdhiru 13 жыл бұрын
why do we need to return sum????? and why is the sum+=bucky[i] things is...why is there a 'i' in the brakcerts pleses someone tell..........
@tysascode
@tysascode 12 жыл бұрын
How would i get just one of the elements?
@0xlemi
@0xlemi 15 жыл бұрын
I agree with you
@askmiller
@askmiller 12 жыл бұрын
does this work for multidimensional arrays?
@Aggregate02
@Aggregate02 15 жыл бұрын
Just break it up into simple parts and use comments to help you understand the process.
@aminmansouri2733
@aminmansouri2733 11 жыл бұрын
cool bro
@johnnyc130
@johnnyc130 15 жыл бұрын
wouldnt an array " int numbers[5]" have 6 elements, 012345. JW
@lindio95
@lindio95 10 жыл бұрын
When i declared sum, the sum is not automatically 0 ?
@filmfreak988
@filmfreak988 9 жыл бұрын
Lindio Pojani So, who knows if you're gonna read this a year after posting or even care anymore, but the issue isn't what sum initially equals. The reason you set sum equal to zero is that, if you used sum previously, it's possible that it already has a non-zero value stored in it.
@GivenFailure
@GivenFailure 12 жыл бұрын
What exactly does the += do
@hamadKhan2k9
@hamadKhan2k9 14 жыл бұрын
please can any body tell me tat wat these headerfiles are use for...fstream and cstdlib
@bondservant4Him
@bondservant4Him 13 жыл бұрын
@XgothicxwarriorX is that correct?
@ArtChartable
@ArtChartable 11 жыл бұрын
Of course robots need programming, but robots can have faster fingers. And it is easy to program which buttons te robot needs to press.
@alirezagyt
@alirezagyt 7 жыл бұрын
how about if the array is two dimensional?
@설리-o2w
@설리-o2w 4 жыл бұрын
I know I am like over 2 years late but for anyone who stumbles upon your question and wonders, you would basically use a nested loop. Something like this. int WorkoutSum(int[2][5]); int main() { int multiarray[2][5]{ {5,5,5,5,5},{5,5,5,5,5}};//Sum is 50 std::cout
@TheLonelyTraveler142
@TheLonelyTraveler142 12 жыл бұрын
*Looks at the titles of tutorials 25 and 26* Me: What if you populated an array with functions with arrays passed into them? 0_O
@tpetree24
@tpetree24 12 жыл бұрын
It's the exact same thing if he was to write "sum = sum + bucky[i]"
@Marty70072
@Marty70072 13 жыл бұрын
why typos :/ ????
@mancoway
@mancoway 12 жыл бұрын
good
@talkingfractal
@talkingfractal 15 жыл бұрын
nope its 5 elements since you count like this 0,1,2,3,4 1,2,3,4,5
@zhir96
@zhir96 14 жыл бұрын
i wonder how hard the advanced coding is if this was the basic :( so hard!
@HawxTeamDelta
@HawxTeamDelta 14 жыл бұрын
btw thanks in advance
@teckninjaprodution
@teckninjaprodution 11 жыл бұрын
you ever master it ?
@TheGreekSkater
@TheGreekSkater 14 жыл бұрын
damn it i understood everything till the last tutorial thats getting hard
@JesusTwoThousand
@JesusTwoThousand 12 жыл бұрын
Better unlearn everything you've learned from this guy and buy a freaking book.
@FredrichNietzsche25
@FredrichNietzsche25 15 жыл бұрын
@BajanCreation Yeah, It is isn't it O.o
@kajakpaddler92
@kajakpaddler92 12 жыл бұрын
DUDE GO EASY ON CAFEINE! LOL
@ChadDrakeTech
@ChadDrakeTech 8 жыл бұрын
Your videos started off well bu now you just rush through everything.
@crateer
@crateer 6 жыл бұрын
Not really, just watch it again. Pretty straightforward tbh.
@thekill761
@thekill761 13 жыл бұрын
@Programmer40 Batch? Batch is a barely used language. I started with Batch when i was 10 years old. And after 2-3 months of programming Batch, i throught that Batch isn't useful language. And so i started programming C. I don't know why am i watching this video.
@JesusRodriguez-is2gj
@JesusRodriguez-is2gj 11 жыл бұрын
........( *-*) i love you; you saved my ass.
C++ Tutorial - 26 - Populating an Array with Functions
7:56
thenewboston
Рет қаралды 76 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 344 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 860 М.
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 579 М.
C++ Tutorial - 2 - The Basic Syntax and Functions
9:33
thenewboston
Рет қаралды 381 М.
Lecture 6: Version Control (git) (2020)
1:25:00
Missing Semester
Рет қаралды 691 М.
struct Basics | C Programming Tutorial
24:44
Portfolio Courses
Рет қаралды 161 М.
DeepSeek is a Game Changer for AI - Computerphile
19:58
Computerphile
Рет қаралды 1 МЛН
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 179 М.
Lecture 1: Introduction to CS and Programming Using Python
1:03:30
MIT OpenCourseWare
Рет қаралды 1 МЛН
C++ Tutorial - 9 - Return Values in Functions
6:45
thenewboston
Рет қаралды 178 М.