C++ POINTERS (2025) - Return multiple values from a function using pointers? PROGRAMMING TUTORIAL

  Рет қаралды 87,088

CodeBeauty

CodeBeauty

Күн бұрын

Пікірлер: 159
@CodeBeauty
@CodeBeauty 3 жыл бұрын
📚 Learn how to solve problems and build projects with these Free E-Books ⬇️ C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook 🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/ Experience the power of practical learning, gain career-ready skills, and start building real applications! This is a step-by-step course designed to take you from beginner to expert in no time! 💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10). Use it quickly, because it will be available for a limited time.
@kevin_mitchell
@kevin_mitchell Жыл бұрын
Thank you. This is a very nice and concise explanation and examples of pointers returning multiple values. I'm learning a lot from these tutorials. For those interested in expanding slightly deeper into this tutorial: The getMinAndMax function assumes the min and max has been set to the min and max of the current array that's sent to the function, but is not guaranteed. For example, in a larger program, if the function has already been used with a different array with a smaller min and a larger max then in the current array sent to the function, then the values returned will be incorrect, unless the min and max is reset to the first element of the current array in use every time the function is called. There are two ways that this could be addressed, such as setting the initial min and max inside the function. Another way could be to use the current getMin and getMax functions as shown below: void getMinAndMax(int numbers, int size, int* min, int* max) { *min = getMin(numbers, size); *max = getMax(numbers, size); }
@tashi7316
@tashi7316 2 жыл бұрын
All of your videos explain the concept so well! I am able to understand a lot without rewatching it. Thanks a lot for making these kind of videos!
@m.s659
@m.s659 3 жыл бұрын
Pointers are super powerful, they can access the memory directly by the address of a variable and change its value easily. Fantastic topic.
@1conscience0dimension
@1conscience0dimension 3 жыл бұрын
so basically passing 2 pointers to a function. so clear and watching it for the second time. I should remember this. I hope
@OpheliaSHolmes
@OpheliaSHolmes 4 жыл бұрын
Love your channel, very clear and well spoken. Subbed!
@CodeBeauty
@CodeBeauty 4 жыл бұрын
☺️🥰
@Unikv
@Unikv 3 жыл бұрын
This exactly what i've been looking for. Thanks a lot!
@CodeBeauty
@CodeBeauty 3 жыл бұрын
🤗🤞😁
@thataverageplayer5680
@thataverageplayer5680 3 жыл бұрын
Did you need to use a pointer? Would the & operator have worked in the function declaration, removing the need for pointers in the function definition?
@chilly2171
@chilly2171 2 жыл бұрын
I was wondering as well. I just used & pointer to send a reference in.
@BonesTormAxeso
@BonesTormAxeso 2 жыл бұрын
If you remove the & (or the addresses of the variables) operator from that function you would't be able to return those two values at once, you probably would had to return an array, for example that contains those two values :P
@thehighlighter8676
@thehighlighter8676 Жыл бұрын
Thanks a lot. I've been struggling with the concepts of pointers for a long time now and your detailed explanations are very helpful. Take love ♥
@thataverageplayer5680
@thataverageplayer5680 3 жыл бұрын
This video is amazing. It really helped me understand pointers and the purpose of & to reference memory addresses.
@rnvj87
@rnvj87 2 жыл бұрын
Finally understood the crux of pointers. Thank you very much.
@FarhanKhan-cx4ke
@FarhanKhan-cx4ke Жыл бұрын
Using a reference in the parameters and writing the body accordingly also works. void getMinAndMax(int[] numbers, int size, int& min, int& max){...} No pointers required.
@MoTharwat-sw2dc
@MoTharwat-sw2dc Жыл бұрын
You are so gifted. Keep shining. ❤
@CodeBeauty
@CodeBeauty Жыл бұрын
Thank you so much, I am happy to share my knowledge and make other people's programming journey easier than mine was 🥰🥰
@yapayzeka
@yapayzeka Жыл бұрын
previous video you said arrayname acts like a first elements pointer. isn't 5:10 passing numbers array is like passing a pointer ? but function waits for a value. it becomes confusing again :/
@lupofroi
@lupofroi 3 жыл бұрын
Great video, you have a great way of presenting the data.
@mohanedemad60
@mohanedemad60 3 жыл бұрын
All your videos are amazing!
@CodeBeauty
@CodeBeauty 3 жыл бұрын
🤗❤️
@mohamedalaa501
@mohamedalaa501 5 ай бұрын
When I try to calculate the size of numbers[ ] inside the getMin( ) using sizeof(numbers) / sizeof(int), it gives that the minimum of numbers[ ] is always numbers[0], i.e. the for loop in getMin( ) is skipped. However, when I send the size as a variable getMin( ), although I found size using the same way, it compiles perfectly. Why do I get this bug?
@IsaacCode95
@IsaacCode95 2 жыл бұрын
thank you very much for these videos ! its just what i needed, i got confused a lot working with pointers, and you make it look really easy (:
@JasminFrancisco-l4p
@JasminFrancisco-l4p 10 ай бұрын
For getmax, how does the program know how to output 26 instead of 6, since theyre both greater than max which is 5
@Ankit-mq6em
@Ankit-mq6em 3 жыл бұрын
I'm falling in love with you😁😁😂🔥🔥your teaching skills are excellent💖💖💖
@funwithshay5945
@funwithshay5945 4 жыл бұрын
Hey, I just started watching your channel and wanted to say thank you for the amazing help you provided. My teacher uses c instead of c++ but I notice that only things like cout and cin are different for now. In c the library is stdio.h tell me if Im right that it is about the same thx!
@CodeBeauty
@CodeBeauty 4 жыл бұрын
They are very similar. They have very similar syntax and code structure and both are close to the hardware - so minor differences here, it should be easy to switch between them. The main difference is that C is a procedural language and it doesn't support OOP, while C++ is both procedural and object-oriented, and because of that, I'd give C++ an advantage over C, but neither one is a bad choice. 🤗
@funwithshay5945
@funwithshay5945 4 жыл бұрын
@@CodeBeauty Ok, thank you!
@virtualrelaxation
@virtualrelaxation Жыл бұрын
Thank you! You help me very much! :) You are amazing! :)
@CodeBeauty
@CodeBeauty Жыл бұрын
You're welcome 😊
@testvb6417
@testvb6417 4 жыл бұрын
Thanks, hope you keep up the serie about c++
@CodeBeauty
@CodeBeauty 4 жыл бұрын
I will ☺️
@chesterapavliashvili1533
@chesterapavliashvili1533 4 жыл бұрын
Nice tutorial, it reminds me out variables from C# and can someone tell me how does System("pause>0") works? it's bit confusing cuz compare is passed as string literall
@CodeBeauty
@CodeBeauty 4 жыл бұрын
system("pause"); is going to pause your console window until you press any key, and if you add >0 to it, it is going to remove junk text You can remove >0 in the program that you're writing, and check out the behavior of your program, and then remove the remaining system("pause") part and check again system("pause") is a platform-specific hack though, and it is not exactly recommended to use. I use it to pause the console window. However, a program that has done its job should quit and return its resources back to the computer, but in this particular situation, we're using system("pause") so that we can pause it and see the output in the console before it closes.
@chesterapavliashvili1533
@chesterapavliashvili1533 4 жыл бұрын
@@CodeBeauty much thanks
@paulzupan3732
@paulzupan3732 2 жыл бұрын
If you want something more platform independent you can use std::cin.get() instead.
@krishnawa_
@krishnawa_ 3 жыл бұрын
it's really helped me thank you so much :)
@shanmugammayan6966
@shanmugammayan6966 Жыл бұрын
What will happen if we didnt declare int size as parameter. Without even that, the prog is running.. can pls tell
@Isaac-dx2vy
@Isaac-dx2vy 8 ай бұрын
Thank you so much!!! It helps me a lot.
@flyindon
@flyindon 4 жыл бұрын
Thank you. I love your videos, They are well presented and have helped me a lot.
@wcchang3321
@wcchang3321 2 жыл бұрын
Thnaks! I try to do it by pass reference. it works too.
@user-ry4ip9ps9x
@user-ry4ip9ps9x 3 жыл бұрын
Thank you this helped me understand pointers better. Is there more to them that I should know? Except for the fact that they allow you to access and edit the original address of a variable.
@mahmoudyosry9409
@mahmoudyosry9409 3 жыл бұрын
Thank you for this great content
@elsafernandatorresferia886
@elsafernandatorresferia886 3 жыл бұрын
Great, thanks! Just one question: Can someone explain me how the program assigns the number of elemts of the array to variable size? I don't see it and I don't understand how the for functions because size is never "initialized" or is never given a value. Tkanhs :)
@thataverageplayer5680
@thataverageplayer5680 3 жыл бұрын
Size is the parameter and 5 is the argument. Meaning, the function declaration is telling us we require an int called size. However, when the function is invoked/called you put the actual int there. CodeBeauty did that. They wrote 5 when calling the function within main. When they write 5 in the argument 5 is then stored within the size variable declared in the function parentheses.
@romainboy9895
@romainboy9895 3 жыл бұрын
Very clear and interesting. Thank you very much !
@FikiMehi
@FikiMehi 9 ай бұрын
thank you sooooooo much. you explain very well.
@andriy_bondarenko
@andriy_bondarenko Жыл бұрын
Thanks! Clear and beautiful!
@alexandresordi346
@alexandresordi346 4 жыл бұрын
Great channel. You explain very well !! One question: If min and max are also arrays. How do return min[ ] and max[ ] using numbers[ ] as a parameter? Thanks!.
@thanaphonsanongkhun3372
@thanaphonsanongkhun3372 2 жыл бұрын
The min and max are not arrays. They simply store a singular data from an array at index
@robertogomezbarrron4968
@robertogomezbarrron4968 Жыл бұрын
@@thanaphonsanongkhun3372 Aren't they pointing to the same memory address ?? numbers[0].
@skeleton_craftGaming
@skeleton_craftGaming Жыл бұрын
​@@robertogomezbarrron4968this by the way is why you should use the STLs array container rather than a pointer, all C style arrays are disappointed to an address that just happens to have the next few words after it allocated as well. (Declaring arrays with [] is a little bit different but still essentially the same thing) There is no distinguishable difference between a pointer to an array and a pointer to a single value in c...
@jmrbautista3974
@jmrbautista3974 4 жыл бұрын
HELP ME PLEASE! 😢 how can i create a program in c++ that is focusing on multiple conversions. (with the use of goto loo, if else, switch) i think these 3 will be use. BIG THANKS IF YOU WILL BE ABLE TO HELP ME ❤️ . THANKS ALSO IF NOT
@TonyAquaro
@TonyAquaro 3 жыл бұрын
Hi Can l use Min as Lowest , low in [10] bars shift 0 Max Highest , High in [10] bars shift 1 total = [21] bars
@alexandruteodor3585
@alexandruteodor3585 3 жыл бұрын
When I have a function like void getMinAndMAx() I pass the parameters by refference (int numbers[], int size, int &min, int & max), and when I call it I write getMinAndMAx(numbers, size, min, max). Is it the same thing as you did? Which method is preferable to use?
@billjohnes9380
@billjohnes9380 3 жыл бұрын
Yes, it is. In your version as in the original one the same things happen behind the scenes. Even the generated code is identical in both cases. The version with references is preferable.
@paulzupan3732
@paulzupan3732 2 жыл бұрын
In my opinion, using pointers is actually preferable to references in that scenario. The reason why I say that is twofold. First of all, it's very clear that you need to pass in a memory address, which will make the caller think twice about whether or not the data at that address will end up being modified inside the function. Second, it allows you to pass in a null pointer, which could be useful in a function like this. Maybe you don't actually care about the max value and you only want the min value. Anyway, that's my two cents on the matter. Both are valid approaches.
@reina4969
@reina4969 2 жыл бұрын
What shortcut do you use to comment out a block of code?
@day4834
@day4834 2 жыл бұрын
CTRL+K, CTRL+C
@ajaymore2693
@ajaymore2693 2 жыл бұрын
@@day4834 no don't make chutiya
@Ijamhuang
@Ijamhuang 2 жыл бұрын
This is amazing!!
@eeshnayani
@eeshnayani 2 жыл бұрын
can you tell me how to have a thousand seperator in c++?
@shreyanshjain4781
@shreyanshjain4781 3 жыл бұрын
nice explanation!!!
@skeleton_craftGaming
@skeleton_craftGaming Жыл бұрын
C++ is moving away from raw pointer semantics, if you want an optional value, you should be using the optional container. If you don't want an optional, you should be passing by T&... Also for the specific examples that you given int& would have been better because it avoids the SEG fault when I you pass null to the min and max value. (Also passing by reference rather than passing by pointer makes it so that the data does not need to be dereferenced in the function and that the address does not need to be passed)
@SandipBhattacharya
@SandipBhattacharya Жыл бұрын
How to return multiple values from a C/C++ function? Usually, a function can only return a single value, using the return mechanism. If you try to return more than one value from a function, only one value will be returned that appears at the rightmost place of the return statement. However, you can return multiple values from the function using the pointer, array, or structure. Using Pointers You can use pointers to return more than one value from a function by passing pointers as function parameters and use them to set multiple values which will then have visibility in the caller function. Using Array If you want to return multiple values of the same data type from a single function, then using an array is best suited because when an array name is passed as an argument then its base address is passed to the function so whatever changes made to the array is changed in the original array. Using Structure Another way to return multiple values from a function is by using structures. Structure is a user-defined datatype in C that can hold several datatypes of the same or different types. The idea is to create a structure variable containing all required data types as its members and return that from the function. We can then retrieve the values from the structure variable inside our caller function.
@yasarasamarathunga7532
@yasarasamarathunga7532 3 жыл бұрын
Hi i am really struggling with a code, Lets say u have a txt file which looks something like, Noun Dog An animal ** Adj Pretty Something beautiful ** Noun Quote A value ** Noun Cinq Something.. ** How can we make the program to display only the words that has a “Q” in it but is not followed by a “U” Result should be something like - “cinq”
@niskander1st
@niskander1st 4 жыл бұрын
Excellent tutorial. However, in the function call "getMinAndMax", the ampersand indicating address is redundant as both "min" and "max" are the addresses of the arrays already.
@vk2ig
@vk2ig 4 жыл бұрын
Really? Why do you say that? min and max both contain the value of numbers[0], which is 5. If you don't pass &min and &max then the getMinAndMax function will receive the address value of 5 in the pointers to min and max.
@igorab1
@igorab1 3 жыл бұрын
Hi! it will be nice not to transfer the size of the array directly, but to calculate it: sizeof array / sizeof array[0]
@paulzupan3732
@paulzupan3732 2 жыл бұрын
That wouldn't work. When you pass an array into a function, it gets coerced into a pointer. Trying to do sizeof(array) would just yield the size of a memory address, not the total size of the array. Even if that did work, since we're no longer passing the length of the array into the function, there would be no way to guarantee that the array wasn't empty, meaning that array[0] could very well seg fault. TL;DR: Good idea in theory, but it wouldn't work in practice.
@vidyprasad
@vidyprasad 3 жыл бұрын
how to write initwindow function in visual c++ please make the video (output full screen )
@mohamedahmed-jv4gz
@mohamedahmed-jv4gz 2 жыл бұрын
great video !
@chandrut5201
@chandrut5201 4 жыл бұрын
Hi i am chandru,when I run this program with the numbers (2,6,-5,67,-89)............It shows both max and min is -89.how can I fix it.?
@onurolce
@onurolce 4 жыл бұрын
One another great tutorial about pointers. But I should warn you a possible crash in your code. Sometimes we can create an array with only 1 element. if we pass this array to your functions then your code will crash. So you should check array size first. Let me explain by code ; int main() { int myArray[] = {76}; cout
@vk2ig
@vk2ig 4 жыл бұрын
If the array has only one element, won't it have a size of 1? In that case, this code for (int i = 1; i < size; i++) won't run beyond loop initialisation, because the loop variable i is initialised to 1, and i is not less than size (1 is not less than 1), so the "for" loop just won't run. In that case the code will return the only value in the array, as the variable min was initialised to the value held in numbers[0].
@arshmaanali714
@arshmaanali714 2 жыл бұрын
can anyone tell me why copy can't be used in main fun ??
@kaustubhpimparkar3585
@kaustubhpimparkar3585 3 жыл бұрын
Misleading title tho. The function is not exactly "returning" multiple values it is just assigning the values of min, max referenced through the pointers and passed as an argument to the function.
@erikstigum9127
@erikstigum9127 2 жыл бұрын
You should really assign default value to min an max in function. You can’t assume user will set it to first element of array.
@JD-eb5qu
@JD-eb5qu 2 жыл бұрын
Thank you somuch mam😍❤️
@fachriyasir661
@fachriyasir661 3 жыл бұрын
Hi Sladina, can I do this method to return an array from a function??
@Uvuvwevwevweonyetenyevwe-zn1gv
@Uvuvwevwevweonyetenyevwe-zn1gv 3 жыл бұрын
Yes if it's dynamically allocated
@paulzupan3732
@paulzupan3732 2 жыл бұрын
Dynamic allocation is an option, but if you don't want to allocate on the heap, you can also add an array parameter and then return the same address
@fsociety692
@fsociety692 4 жыл бұрын
@CodeBeauty can u please make a video on how to pass a function to another function ny refernce that we use one function attribute in other function
@tarekrio6438
@tarekrio6438 2 жыл бұрын
So helpful thanks
@miguelangelgonzalezcontrer2434
@miguelangelgonzalezcontrer2434 3 жыл бұрын
oh por dios eres la mejor!!!
@CodeBeauty
@CodeBeauty 3 жыл бұрын
🙏💙
@learntoearn6612
@learntoearn6612 3 жыл бұрын
Thumb up @TrueCodeBeauty 🙏☝️
@sivasainagireddi7956
@sivasainagireddi7956 3 жыл бұрын
Damnn🔥 Why can't I hit the like button twice🤕
@canaryframes2847
@canaryframes2847 2 жыл бұрын
Any reason you can't you just do this? void getMinAndMax(int numbers[], int size, int &min, int &max)
@cambridgebreaths3581
@cambridgebreaths3581 4 жыл бұрын
Saldina, if one dedicates 5 hours per day of serious C++ learning, how long will it take to be an advanced C++ programmer? Subscribed and Thanks
@CodeBeauty
@CodeBeauty 4 жыл бұрын
5 hours every day is a lot of time, and I'm not sure if it is maintainable long term. I'd aim for 2-3 hours per day, stay consistent, do that for a year and then start looking for junior dev positions, and continue learning. You are not going to be a hell of a developer after one year, but you might get a chance in a company, and if you do, find yourself a good senior dev who is willing to help and guide you and don't let go! Don't chase the money or different benefits that companies offer if you are just starting. Free food, team buildings, remote work, gym memberships, playing games at work... 🚫 The only important thing at this stage is to get experience and knowledge, and once you have that, you'll have all the benefits and money that you want. But, it'll be a marathon, not a sprint. 😉
@cambridgebreaths3581
@cambridgebreaths3581 4 жыл бұрын
@@CodeBeautyGreat. will follow your advice. And will comment after a year. Wish you all the very best.
@nines7588
@nines7588 3 жыл бұрын
u saved me! thanks
@ArjanvanVught
@ArjanvanVught 3 жыл бұрын
Using pointers is C-like, in C++ you would use references in the function argument
@mustanggt-5006
@mustanggt-5006 2 жыл бұрын
i love your videos
@RAMANKUMARGCEBIT
@RAMANKUMARGCEBIT 2 жыл бұрын
very helpful
@kelvinwilliams2908
@kelvinwilliams2908 3 жыл бұрын
I followed it through but it sounded like a complicated way to find the max and min values in an array. Is there an easier way to do it, or were you just showing us how to do it using pointers?
@TheTin123456789
@TheTin123456789 3 жыл бұрын
I think she used this example just to demonstrate how to use pointers. In this case, we can find max value or min value without using pointers. Please correct me if I am wrong. void getMinMax(int input[]) { int min = input [0]; int max = input[0]; for (int i = 1; i < sizeof(input); i++) { if (input[i] < min) min = input[i]; if (input[i] > max) max = input[i]; } cout
@alfiankhaulany5326
@alfiankhaulany5326 3 жыл бұрын
can't understand a thing, I keep watching you for a whole video XD
@pratyayganguli9693
@pratyayganguli9693 3 жыл бұрын
This is so interesting
@TheSoreven
@TheSoreven 3 жыл бұрын
Actually that is not what is called returning multiple values from a method, just passing multiple references and changing them. Returning multiple values can be done with something like 'tuple' or a custom made class/struct.
@davidfulgencio9546
@davidfulgencio9546 2 жыл бұрын
You're right. Firstly, the function used in the example is of the void type which indeed means no return, then we cannot accurately talk about multiple return.
@nathnaeltsegaye4831
@nathnaeltsegaye4831 3 жыл бұрын
your magic !!
@billjohnes9380
@billjohnes9380 3 жыл бұрын
Using int instead of size_t for an array size is a severe error.
@ericmccarty4389
@ericmccarty4389 3 жыл бұрын
Your intro sound is super loud compared to your content volume. This info was super helpful though, thank you
@amiganer681130
@amiganer681130 3 жыл бұрын
Using a "struct" with min and max, but I think the (real) return value will be a pointer to the struct variable, I think it is not realy seen as a pointer.
@nnamdiobasi3359
@nnamdiobasi3359 2 жыл бұрын
Hey Saldina, I'm new to c++ and your videos are really helping. I have a problem with this example as i do not fully understand the need for pointers in it. Here is my own code: #include #include void maxminNum(std::vector nums){ //for max: int max = nums[0]; int min = nums[0]; for(size_t i{1}; i < nums.size(); i++){ if(nums[i] > max){ max = nums[i]; } if(nums[i] < min){ min = nums[i]; } } } int main(){ std::vector vect {3, 5, 1, -3, 8}; maxminNum(vect); return 0; } Please explain why my code which passes by value may be affected and why we should pass by reference as the code works as it should.
@karelchlumecky2574
@karelchlumecky2574 2 жыл бұрын
Hey. Your code works good for min and max but if you want use max and min values in function main you can't. If you declare variable in function, this variable on the end of loop will disappear. So if you need use in main or in another function your max or min (and you don't want working with return types in function maxminNum) you need declare variables max and min in main function and send pointer like a parameter to your function.
@knanzeynalov7133
@knanzeynalov7133 Жыл бұрын
Chatgpt
@m7s293
@m7s293 3 жыл бұрын
Where is the task?
@Amir-z3b5p
@Amir-z3b5p 8 ай бұрын
Greatly
@lamalamalex
@lamalamalex Жыл бұрын
I like that idea, but why not just do it in one step by calling by reference?
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 2 жыл бұрын
I still don't know the point of pointers. Dang. I'll keep trying
@sdy.deathcall9608
@sdy.deathcall9608 Жыл бұрын
Bro same. The problem is i can get those functions working without it.
@subee128
@subee128 2 жыл бұрын
Thanks
@pseudoname777
@pseudoname777 Жыл бұрын
Can someone explain the purpose of pointers I’ve watched most of her videos on them (maybe haven’t gotten to the one with the answer) But pointers, so far, seem like just another option instead of nested if statements. Why use them? I can pass multiple if statements in a single function and return the value. Why go through its address and dereferencing them
@and_then_I_whispered
@and_then_I_whispered 2 жыл бұрын
I think, we can just pass those max and min by reference, I mean without passing addresses.
@mirthun1012
@mirthun1012 3 жыл бұрын
give me a heart sis🥰
@eliaspianomusic
@eliaspianomusic 3 жыл бұрын
This is pretty much what you understand as "call by reference", am I right? Just to make sure I connect the right dots.
@eliaspianomusic
@eliaspianomusic 3 жыл бұрын
Oh yeah, it is, just saw it in the video description! Thanks a lot for writing it in there as well! Great and very helpful video(s)!!
@rudybeshara
@rudybeshara Жыл бұрын
kess emmik shou awiye
@mitnickcodehelper4392
@mitnickcodehelper4392 3 жыл бұрын
My answer is a short program in c++ this: #include class CodeBeautyMinMax { private: int min, max; /* Disallow object creation without an parameter */ private: CodeBeautyMinMax(){} public: CodeBeautyMinMax( int *paramArr ) { /* min and max should be zero */ this->min = this->max = 0; this->findMinAndMax( paramArr ); } private: void findMinAndMax( int *paramArr ) { if ( paramArr == NULL ) return; /* first element of array is now stored into min and max variable*/ this->min = this->max = *paramArr; /* Enter the While-Loop again if you do not find a 0 "Zero" */ while( *(++paramArr) != 0 ) { /* To reach the next element of the array - This does the trick: ++paramArr */ /* This is the same as above into the Video - but shorter =) */ this->min = ( *paramArr < this->min ? *paramArr : this->min ); this->max = ( *paramArr > this->max ? *paramArr : this->max ); } } public: int getMin(){ /* Get only the min-value */ return this->min; } public: int getMax(){ /* Get only the max-value */ return this->max; } public: void getMinAndMax( char* buf ) { /* It would work with sstream as well - but I am a old school guy =) Combine string with variable like this */ sprintf( buf, "min is: %d max is %d", this->min, this->max ); } }; int main(void) { int arrValues[7] = { 1, -5, 14, 6, -20, 99, 0 }; int *ptr = arrValues; CodeBeautyMinMax *cbmm = new CodeBeautyMinMax( ptr ); std::cout
@fusiontv5269
@fusiontv5269 3 жыл бұрын
7:15
@sunstrumsharam5388
@sunstrumsharam5388 Жыл бұрын
I try by reference and it does the same, it is different, than using with pointer? (your videos are awesome) void MinandMax(int array[],int size,int& pMin,int& pMax) { for(int i=0;i array[i]){pMin = array[i];} if(pMax < array[i]){pMax = array[i];} } } int main() { int arr[5] = {5,4,3,8,2}; int min = arr[0]; int max = arr[0]; MinandMax(arr,5,min,max); std::cout
@farikunaziz6504
@farikunaziz6504 4 жыл бұрын
can i use a function pointer*
@neurothoughtmachine
@neurothoughtmachine 2 жыл бұрын
// using a pointer to pull data out of a function.... // using a pointer to pass a reference to an array #include using namespace std; int* func_GetArray(int numbers[], int size, int min, int max, int* numbers_out) { for (int var_i = 0; var_i < size; var_i++) { if (numbers[var_i] < min) { numbers_out[0] = numbers[var_i]; } if (numbers[var_i] > max) { numbers_out[1] = numbers[var_i]; } } return numbers_out; } int main() { int numbers[5] = { 5, 6, -2, 29, 6 }; int numbers_out[2]; int min = numbers[0]; int max = numbers[0]; // placing a fixed value into a function's argument list is a no-no. // Always use a variable or a pointer to a variable when passing values into a function. int size = 5; func_GetArray(numbers, size, min, max, numbers_out); cout
@diman1ght491
@diman1ght491 2 жыл бұрын
OMG! Still No tuples, really?
@ahmedassal8710
@ahmedassal8710 3 жыл бұрын
In my humble opinion this video should be renamed to be "make your Function change in variables which exist in the main function using pointers" OR something like that I just not convinced with it
@kxyt4reel
@kxyt4reel 4 жыл бұрын
Sorry, where exactly do you return more than one value?
@colinmaharaj
@colinmaharaj 3 жыл бұрын
...or references
@Alphabet_-_
@Alphabet_-_ 4 жыл бұрын
I *Miss You
@TT-yi9nd
@TT-yi9nd 3 жыл бұрын
// FindMinAndMaxWithoutPointers.cpp : This file contains the 'main' function. Program execution begins and ends there. #include using namespace std; class FindMin_Max { public: int Max; int Min; FindMin_Max() { Max = 0; Min = 0; } void showInfo(int array [], int size) { Max += array[0]; Min += array[0]; for (int i = 1; i < size; i++) { if (array[i] > Max) Max = array[i]; if (array[i] < Min) Min = array[i]; } cout
@chrischoir3594
@chrischoir3594 2 жыл бұрын
better practice to return a struct
@noitnettaattention
@noitnettaattention 4 жыл бұрын
Well... I Looooooovvvveeeeeeee you ! ;)
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 336 М.
How To Return An Array From A Function | C Programming Tutorial
13:01
Portfolio Courses
Рет қаралды 70 М.
The C++ Lambdas
11:44
Code for yourself
Рет қаралды 4,6 М.
Return Multiple Values From A Function | C++ Tutorial
11:43
Portfolio Courses
Рет қаралды 4,5 М.
Functions vs Classes: When to Use Which and Why?
10:49
ArjanCodes
Рет қаралды 170 М.
SMART POINTERS in C++ (for beginners in 20 minutes)
24:32
CodeBeauty
Рет қаралды 106 М.