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

  Рет қаралды 86,188

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 11 ай бұрын
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); }
@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
@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!
@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.
@OpheliaSHolmes
@OpheliaSHolmes 4 жыл бұрын
Love your channel, very clear and well spoken. Subbed!
@CodeBeauty
@CodeBeauty 4 жыл бұрын
☺️🥰
@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.
@thataverageplayer5680
@thataverageplayer5680 3 жыл бұрын
This video is amazing. It really helped me understand pointers and the purpose of & to reference memory addresses.
@Unikv
@Unikv 3 жыл бұрын
This exactly what i've been looking for. Thanks a lot!
@CodeBeauty
@CodeBeauty 3 жыл бұрын
🤗🤞😁
@rnvj87
@rnvj87 2 жыл бұрын
Finally understood the crux of pointers. Thank you very much.
@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 11 ай бұрын
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 ♥
@lupofroi
@lupofroi 3 жыл бұрын
Great video, you have a great way of presenting the data.
@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 (:
@MoTharwat-sw2dc
@MoTharwat-sw2dc 11 ай бұрын
You are so gifted. Keep shining. ❤
@CodeBeauty
@CodeBeauty 11 ай бұрын
Thank you so much, I am happy to share my knowledge and make other people's programming journey easier than mine was 🥰🥰
@mohanedemad60
@mohanedemad60 3 жыл бұрын
All your videos are amazing!
@CodeBeauty
@CodeBeauty 3 жыл бұрын
🤗❤️
@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.
@andriy_bondarenko
@andriy_bondarenko Жыл бұрын
Thanks! Clear and beautiful!
@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.
@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)
@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.
@testvb6417
@testvb6417 4 жыл бұрын
Thanks, hope you keep up the serie about c++
@CodeBeauty
@CodeBeauty 3 жыл бұрын
I will ☺️
@romainboy9895
@romainboy9895 3 жыл бұрын
Very clear and interesting. Thank you very much !
@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 3 жыл бұрын
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].
@mahmoudyosry9409
@mahmoudyosry9409 3 жыл бұрын
Thank you for this great content
@krishnawa_
@krishnawa_ 3 жыл бұрын
it's really helped me thank you so much :)
@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!
@Isaac-dx2vy
@Isaac-dx2vy 7 ай бұрын
Thank you so much!!! It helps me a lot.
@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.
@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.
@virtualrelaxation
@virtualrelaxation Жыл бұрын
Thank you! You help me very much! :) You are amazing! :)
@CodeBeauty
@CodeBeauty Жыл бұрын
You're welcome 😊
@FikiMehi
@FikiMehi 8 ай бұрын
thank you sooooooo much. you explain very well.
@alexandresordi346
@alexandresordi346 3 жыл бұрын
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...
@Ijamhuang
@Ijamhuang 2 жыл бұрын
This is amazing!!
@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
@miguelangelgonzalezcontrer2434
@miguelangelgonzalezcontrer2434 3 жыл бұрын
oh por dios eres la mejor!!!
@CodeBeauty
@CodeBeauty 3 жыл бұрын
🙏💙
@Ankit-mq6em
@Ankit-mq6em 3 жыл бұрын
I'm falling in love with you😁😁😂🔥🔥your teaching skills are excellent💖💖💖
@shreyanshjain4781
@shreyanshjain4781 3 жыл бұрын
nice explanation!!!
@JasminFrancisco-l4p
@JasminFrancisco-l4p 9 ай бұрын
For getmax, how does the program know how to output 26 instead of 6, since theyre both greater than max which is 5
@tarekrio6438
@tarekrio6438 2 жыл бұрын
So helpful thanks
@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 :/
@mohamedahmed-jv4gz
@mohamedahmed-jv4gz 2 жыл бұрын
great video !
@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
@subee128
@subee128 2 жыл бұрын
Thanks
@igorab1
@igorab1 2 жыл бұрын
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.
@nathnaeltsegaye4831
@nathnaeltsegaye4831 3 жыл бұрын
your magic !!
@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.
@RAMANKUMARGCEBIT
@RAMANKUMARGCEBIT 2 жыл бұрын
very helpful
@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.
@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)!!
@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.
@pratyayganguli9693
@pratyayganguli9693 3 жыл бұрын
This is so interesting
@JD-eb5qu
@JD-eb5qu 2 жыл бұрын
Thank you somuch mam😍❤️
@eeshnayani
@eeshnayani 2 жыл бұрын
can you tell me how to have a thousand seperator in c++?
@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
@vidyprasad
@vidyprasad 3 жыл бұрын
how to write initwindow function in visual c++ please make the video (output full screen )
@ericmccarty4389
@ericmccarty4389 3 жыл бұрын
Your intro sound is super loud compared to your content volume. This info was super helpful though, thank you
@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.
@mohamedalaa501
@mohamedalaa501 4 ай бұрын
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?
@sivasainagireddi7956
@sivasainagireddi7956 3 жыл бұрын
Damnn🔥 Why can't I hit the like button twice🤕
@mustanggt-5006
@mustanggt-5006 2 жыл бұрын
i love your videos
@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 3 жыл бұрын
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.
@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
@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
@Amir-z3b5p
@Amir-z3b5p 7 ай бұрын
Greatly
@shanmugammayan6966
@shanmugammayan6966 Жыл бұрын
What will happen if we didnt declare int size as parameter. Without even that, the prog is running.. can pls tell
@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
@canaryframes2847
@canaryframes2847 2 жыл бұрын
Any reason you can't you just do this? void getMinAndMax(int numbers[], int size, int &min, int &max)
@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
@lamalamalex
@lamalamalex Жыл бұрын
I like that idea, but why not just do it in one step by calling by reference?
@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.
@yasarasamarathunga7532
@yasarasamarathunga7532 2 жыл бұрын
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”
@billjohnes9380
@billjohnes9380 3 жыл бұрын
Using int instead of size_t for an array size is a severe error.
@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.?
@learntoearn6612
@learntoearn6612 3 жыл бұрын
Thumb up @TrueCodeBeauty 🙏☝️
@mirthun1012
@mirthun1012 3 жыл бұрын
give me a heart sis🥰
@arshmaanali714
@arshmaanali714 2 жыл бұрын
can anyone tell me why copy can't be used in main fun ??
@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
@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.
@m7s293
@m7s293 3 жыл бұрын
Where is the task?
@alfiankhaulany5326
@alfiankhaulany5326 3 жыл бұрын
can't understand a thing, I keep watching you for a whole video XD
@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
@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
@farikunaziz6504
@farikunaziz6504 4 жыл бұрын
can i use a function pointer*
@rudybeshara
@rudybeshara Жыл бұрын
kess emmik shou awiye
@fusiontv5269
@fusiontv5269 3 жыл бұрын
7:15
@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
@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
@colinmaharaj
@colinmaharaj 3 жыл бұрын
...or references
@noitnettaattention
@noitnettaattention 4 жыл бұрын
Well... I Looooooovvvveeeeeeee you ! ;)
@Alphabet_-_
@Alphabet_-_ 4 жыл бұрын
I *Miss You
@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
@diman1ght491
@diman1ght491 2 жыл бұрын
OMG! Still No tuples, really?
@chrischoir3594
@chrischoir3594 Жыл бұрын
better practice to return a struct
@smpbih
@smpbih 4 жыл бұрын
:*
@mahmoud-khaled-abo-elmagd
@mahmoud-khaled-abo-elmagd 3 жыл бұрын
epic
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 31 МЛН
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН
The C++ Lambdas
11:44
Code for yourself
Рет қаралды 4,4 М.
How To Return An Array From A Function | C Programming Tutorial
13:01
Portfolio Courses
Рет қаралды 69 М.
C++ Examples - Pass by Value vs Reference vs Pointer
11:53
Caleb Curry
Рет қаралды 23 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 328 М.