C Programming Tutorial # 26 - Passing Pointers to Functions - Part 1 [HD]

preview_player
Показать описание

In this tutorial we learn about how to pass pointers to a function as parameters. This way we can return more than one value from a function. As an example, we learn how to write a function that returns twice and thrice of a given integer.

This tutorial is part of the following series:
Рекомендации по теме
Комментарии
Автор

@Learnorama
After having watched all 44 of your videos I can attest to how great the quality of work is. I apologize for being so quick to pass judgment before. Thanks for everything!

doubleja
Автор

@Peter8831 Hi Peter. This is just one of the purposes. There are a couple of more reasons One is the size of the parameter. Remember these parameters are pushed on stack, and hence if you pass a big structure as value, it is copied on the stack and it can raise the size of the stack too much. Secondly, when you really want to manipulate the address inside the function for whatever reason. For example, when working with arrays or strings. And in embedded system, memory registers etc.

Learnorama
Автор

You explained this concept pretty well. However, there's one thing that I might phrase differently, and perhaps you're not the only one who says it this way. Personally, I think it is more logical to say you are creating a pointer as the function's dummy argument, and you are passing a "pointee" (the actual variable to which a pointer points) to it from the main function. It may be a good idea to use the pointer & pointee terminology. Otherwise, everything is great!

Peter
Автор

A conceptual idea that I'm wondering about, and I'd actually appreciate if you can tell me if this is correct or wrong, is the true purpose of pointers and pointers as function arguments. The limit of functions is that, with no matter how many parameters you have, you can only return one value Nonetheless, many times returning multiple values, or at least having a lasting/direct effect on multiple values in the main function while inside a local function is what a programmer desires. Cont...

Peter
Автор

@doubleja No problem. I am glad I could help.

Learnorama
Автор

...cont from before. Aside from pointers giving a programmer more flexibility in terms of more direct memory adress control, they are extremely useful in the very situations described below. My guess is that by pointing to actual parameters from the main function, you can control their values directly while the local function is occurring and thereby a programmer has the same effect as returning multiple values from functions. So I'm wondering if this is one of the main purposes of pointers.

Peter
Автор

@doubleja Hi, thanks for the comment. I am sure this stuff has been covered by many it is just the style and depth of coverage that counts. When I started I did not intend to charge for it. But when it started consuming lots of time and money for me, I had no choice but to apply a minimal fee. There are still most of the tutorials absolutely free. Only a few locked. And I don't think asking a small minimal fee for all this service is asking a lot. But thanks for your comment.

Learnorama
Автор

Great job my friend! It just amazes me that some free loaders wouldn't even willing to pay $19 for half year access to your absolutely the best C++ tutorials on web...

joshsha
Автор

You are really an AWESOME guy...!These tutorials are really helping me a lot....!

Автор

hey sohail, i appreciate the videos but why cant we watch part 2 for most of the videos anymore? it says its private... im already subcribed to your vids. hope you can fix this so we can learn more :) thx!

natlwc
Автор

Do the pointer vs. array thing work on different types? like pointer[2], pointer++, pointer--, etc. Or does that work only for int?

thKyuubi
Автор

hi thanx for the tutorial on functions, really help me a lot in understanding programming.

years
Автор

I appreciate what you're doing, but most of this stuff is already covered for free by other youtube users. Asking for subscribing and liking your videos should be enough.

doubleja
Автор

@digi198816 Agreed, asking for viewers to Subscribe + Become A Fan is tedious enough... then we factor in the idiotic annotations.

Fail.

Plenty more free C++ videos on YouTube.

DYLX
welcome to shbcf.ru