Sharma
Sharma

Reputation: 71

What is the difference between Pointer and strings?

What is the difference between a pointer and array or they are same? As a array also works with poiter arithematic so it can be said that an array is nothing but pointer to its fitst element.

Upvotes: 0

Views: 161

Answers (1)

Sharma harsh
Sharma harsh

Reputation: 220

They both are different by the following differences:-

int array[40];
int * arrayp;

Now if you will try to see the size of both then it will be different for pointer it will same everytime whereas for array it varies with your array size

sizeof(array);\\Output 80
sizeof(arrayp);\\Output 4(on 32-bit machines)

Which means that computer treats all the offsprings of integers in an array as one which could not be possible with pointers.

Secondly, perform increment operation.

array++;\\Error
arrayp++;\\No error

If an array could have been a pointer then that pointer's pointing location could have been changes as in the second case with arrayp but it is not so.

Upvotes: 2

Related Questions