C Programming - Arrays - Discussion

Discussion Forum : Arrays - General Questions (Q.No. 2)
2.
What does the following declaration mean?
int (*ptr)[10];
ptr is array of pointers to 10 integers
ptr is a pointer to an array of 10 integers
ptr is an array of 10 integers
ptr is an pointer to array
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
64 comments Page 5 of 7.

Vikash kumar said:   1 decade ago
As we know ptr holds the address of variables, and *ptr means what is the value of variables on that address.

Sornalatha said:   1 decade ago
(*ptr) is a pointer. It point out the array of value [10]. So option B is correct.

Rahul kumar singh said:   1 decade ago
int (*ptr)[10] first we have to do the operation in bracket. So in bracket *ptr is there, notice the first variable name it is ptr then go right to the variable there is end bracket then move left of your variable indirection operator is there then again move towards right of ptr we get subscript so there it is array then left of ptr int is there. So ptr is a pointer to an array of 10 elements of type integer.
(1)

Yuvraj said:   1 decade ago
Hey, I m not getting difference between array of pointer and pointer of array. Can you please explain me?
(1)

Abdul Quadir said:   1 decade ago
Int (*ptr)[10];

It's a pointer to an array of 10 integers.

Notice that the array doesn't have a name of its own. We're using the pointer "ptr" to access the array.

The array will be created anywhere in the memory and the only way to access the array is via the pointer "ptr".

Chotu said:   9 years ago
Explain the answer of this question.

Ankit said:   9 years ago
@Chotu.

When we declare an array, say int a[10];

In above declaration 'a' is acting as a pointer because it holds the base address of array (the location from where it starts storing the values in memory continuously).

But in above example, they just declare the array name as pointer explicitly.

Hence, it is just same as the array declaration on 10 integers.

Arman said:   9 years ago
int (*ptr)[10] - *ptr is a pointer to an array of 10 integers but how?

Because the size of the array is stored in [ ] this form and we seen the 10 is stored [10] like so explain it 10 integer or 10 sizes of the array.

Bhuvi said:   8 years ago
@ALL.

#include<stdio.h>
int main()
{
int a=5;
printf("%d %d %d %d %d", a++, a--, ++a, --a, a);
return 0;
}

This depends on the compiler, we don't know the order in which this expression is evaluated is either right to left or left to right.

Abhishek said:   8 years ago
Here, int (*ptr)[10]; - meaning ptr is a pointer to an array of 10 integers.

BUT what will be the NAME of the Array here(which array there is no name given to any array)?


Post your comments here:

Your comments will be displayed after verification.