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 4 of 7.

Srilakshmi said:   1 decade ago
Array size is represented in []ie. , no. Of elements contained in it * represents for a pointer so ptr is a pointer to an array of 10 integers since the return type is specified as int.

Rajeev Tomar said:   1 decade ago
Here [10] is the size of array (as in [], always size of array is represesnted) and *ptr is a pointer pointing the particular array. Means there in the memory, there is an array consisting of 10 blocks of integer type and a pointer is pointing to that particular array.

This array would be accessed by that pointer.

Raju said:   1 decade ago
#include<stdio.h>
int main()
{
int a=5;
printf("%d %d %d %d %d", a++, a--, ++a, --a, a);
return 0;
}
when i compile this programme in gcc compiler the output as 4 5 5 5 5
because,programme excute from right to left so
a=5
--a predecrement so --a=4
++a preincrement so ++a=5
a-- postdecrement so actual value is 4,but first a value 5 is printed then it will decrement.
a++ postincrement so actual value is 5,but first a value 4 is printed then it will increment.
but all preincrements and predecrements get final a value 5 and postdecrements & postincrements doesn't change.
then the output is 4 5 5 5 5.

Disha bhatt said:   1 decade ago
Here size of an array is assinged to 10 and * has been used to declare pointer funtion so compiler will automatically consider it as an pointer funtion.Here it simply means it is a pointer funtion consisting of 10 elements.

Balu said:   1 decade ago
First it will read the variable part i.e, (*ptr) and after that it will go anti-clock wise direction then it will read array part([]). Then it will go to before (*ptr)[10]. There is nothing so it will leave.

Amr Gadallah said:   1 decade ago
char *ptr[10]; is an array of 10 pointers to characters.

char (*ptr)[10]; pointer to array of 10 characters.

Tharun said:   1 decade ago
void main()
{
int (*d)[10];
d[0] = 7;
d[1]=10;
printf("%d\n",*d);
}

It should print 10 but compiler is showing error such as follows:

test.c:4:7: error: incompatible types when assigning to type \'int[10]\' from type \'int\'

Kumarachary said:   1 decade ago
@Vijayalaxmi is right.

We have to see the priority () have highest priority.

So int (*ptr)[] read it as pointer to array of integers.

If () is not there then int *ptr[] start with [] and it means array of pointers of type integers.
(1)

Sanju said:   1 decade ago
Here ptr is the pointer it is represented by using *...! then the symbol [] shows that it is an array and 10 implies the size of that array.

Sankar said:   1 decade ago
If any one clear about ptrs please explain clearly. Because I don't understanding anything belong to this.


Post your comments here:

Your comments will be displayed after verification.