i want to clear a doubt...
please check out the following codes..

int function (int p[])
{
  //sm code
}

another style is :

int function (int *p)
{
  // sm code
}

here i am passing an array to both the functions...and one receives it through p[] and another through *p....
then what is the difference between both styles ??
or just that the former uses subscript and the latter dereferences the pointer to access the values... ??
please clear out my doubt...

Recommended Answers

All 4 Replies

>>then what is the difference between both styles ??
The first is most definitely an array. The second may or may may not be an array because it could also be a pointer to a single int object. function() must be made smart enough to know whether *p is a pointer to an object or an array. In both versions of the function it must also know how many elements are in the array.

>>then what is the difference between both styles ??
The first is most definitely an array. The second may or may may not be an array because it could also be a pointer to a single int object. function() must be made smart enough to know whether *p is a pointer to an object or an array. In both versions of the function it must also know how many elements are in the array.

bro..
but i am passing an array to both the functions...
i just want to know the difference at that time... :|

>> just want to know the difference at that time...
There is no difference other than what I already mentioned. Its only two different ways to code arrays. The code inside the function is identical in both cases.

ohkkk ... :)
thnxx... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.