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

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.

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\'

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.

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.

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".

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.


Post your comments here:

Your comments will be displayed after verification.