Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why we use pointer(*) to return an array from other function to main function?

0 votes
asked Apr 15, 2018 by Sufyan05 (130 points)

1 Answer

0 votes
answered Apr 22, 2018 by LISHI !! (140 points)

If  an array has to be returned to the main function from other function as a whole, the name of the array is returned.

For eq. you have an array a[10]={10,20,30}, you will return the entire array by using it's name i.e. "a"

"a" points to the base address of the first element a[0]

i.e

a=&a[0]

which makes "a" a pointer, and hence a pointer in the main function is made to receive "a", which points to the address of the first element of the array.

hope this helps:)

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...