Returning Pointers

preview_player
Показать описание
C Programming: Returning Pointers in C Programming.
Topic discussed:
1) Finding the mid of an array using the returning pointers.

Music:
Axol x Alex Skrindo - You [NCS Release]

#CProgrammingByNeso #CProgramming #Pointers #ReturningPointers #PointersInC
Рекомендации по теме
Комментарии
Автор

I was just confused with what is "returning a pointer " means, this one video made me clear.
Heartiest Thanks to NESO Academy for bringing this video .

molyoxide
Автор

This was crisp yet nailing all the points - thanks so much for the explanations.These types of explanations acts well for refreshers and anyone who wants to get a reason behind a syntax.Awesome.

rajcodes
Автор

Important point :Array is passed into a function always by, call by address.

rsingh
Автор

Thank you so much for this fantastic c tutorial! Your explanation was incredibly clear and made the topic easy to understand but I just want to clarify that there's no need to use pointers for finding the middle element of an array in this specific problem. You can easily calculate the middle element using array indices as shown in this code:
#include <stdio.h>
int findMid(int arr[], int len) {
return arr[len / 2];
}
int main() {
int a[] = {1, 2, 3, 4, 5};
int n = sizeof(a) / sizeof(int);
printf("The middle of the array is: %d\n", findMid(a, n));
return 0;
}
Pointers would be more relevant when you need to manipulate or traverse the array dynamically or when you want to pass the array itself to a function.
However, if you want to use pointers for educational purposes or as an alternative approach, you can certainly do so.

mcuvijx
Автор

One day NESO will surpass college degrees . They are a waste even now anyways . But great work you guys doing :D

USBEN.
Автор

4:22 it's better to refer to it as a stack variable, knowing that the stack pops that variable after the scope ends. Look up allocating on stack vs. heap.

dantheman
Автор

Thanks a lot ! 30 minutes with you and I understood what a pointer was and how to use them ! My Udemy class had a 3h chapter for pointers, I guess you just saved 2h30 of my time !!

oluap
Автор

I watched some of the videos only yet but still I just felt the need to thank you so much for awesome videos, presentations and clear / insightful explanations.

mc-tiuq
Автор

Sir, as you said passing address of local varible is an error, but in your example in *findMid function, collected ( int a[], and int n), so even having same name of these varibles but it is local to findMid func.... So how could you return address of &a[n/2] ?

saramostafa
Автор

Sir all your Discrete Mathematics videos are awesome after watching your videos, I dont want to watch other vieos of Discrete Mathematics, So please upload Videos of Discrete Mathematics.


TechnicalWaves
Автор

If I understand correctly.

Suppose we have 4 bytes integers:
In the line int [a] I would have mentioned: 4 x 5 = 20
And the next line boils down to: 20 / 4 = 5

And others have mentioned - this *findMid function resides on the stack and dies immediately after returning back to the main scope.

Anyway thanks for your videos.

grimvian
Автор

I watched many videos in this list and they helped me. thank you

youssefmohammed
Автор

Note: Arrays are passed by reference not by value

mdwahid
Автор

Your program shows an error, If I type *findMid it shows implicit declaration, but when I type just findMid it works correctly

roshanmhatre
Автор

Plzzz make complete videos on os and computer networking plzz

adarshrai
Автор

2:01. Sorry if dumb question but when you pass the array an over to the *find mid function, aren't you passing a copy of the array over? so the pointer that gets passed back is a pointer to the copy of *a local to the find mid function? So after the function executes and the active frame is removed from the stack shouldn't the address be invalid?

bramkesseler
Автор

but when the array variable is even
what should we do?

saifulislamsarfaraz
Автор

but a[] is also be a local variable in first program

addagallanaresh
Автор

#include<stdio.h>
int *findmid(int a[], int len);
int main()
{
int a[]={1, 2, 3, 4, 5};
int len=sizeof(a)/sizeof(a[0]);
int *mid = findmid(a, len);
printf(" Ans: %d ", *mid);
return 0;
}
int *findmid(int a[], int len)
{
return &a[len/2];
}


OUTPUT :

Ans: 3
Process returned 0 (0x0) execution time : 0.008 s
Press any key to continue.

tamimurrahman
Автор

bro i just have one doubt in this video that why did you used the dereference operator in the prefix of the function findMid?? like *findMid ....is there any use of doing so ?
i know i wont get a reply //just trying as m late

sanjaymishra