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.

JAY said:   6 years ago
Could you please explain the question.

Rupa said:   6 years ago
Could you please explain the question?

Sundar said:   1 decade ago
@Chris

The given output '4 5 5 4 5' is matches in Turbo C - 16 OS (DOS).


But, I tried in GCC, the details are as below:

Warnings:=

prog.c: In function 'main':
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined
prog.c:5: warning: operation on 'a' may be undefined

Output:=

4 5 5 5 5

Please can anyone explain with full details here. Thanks in advance.

Chitra said:   1 decade ago
*ptr is a pointer and [10] is array is array declaration.

Neha said:   1 decade ago
Can you explain me the concept?

Ravikumar said:   1 decade ago
We can use a * sometimes to declare the array both are same that is way answer is b.

Vijayalaxmi said:   1 decade ago
Here 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.

Avijit said:   1 decade ago
ptr is a pointer,which is a type of int.ptr is an array.

Kuldeep chaudhary said:   1 decade ago
pointer of array is declared as type (*p)[14]
array of pointers is declared as type *p[14]

Gautam jangra said:   1 decade ago
int (*ptr)[10]
also we can write it as
int *ptr[10]

this line says that ptr is a pointer type variable which stores the address of first element of a 10 elements array list
as we know that array is continous memory type allocation.....


Post your comments here:

Your comments will be displayed after verification.