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:
65 comments Page 5 of 7.

Gautam jangra said:   2 decades 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.....

Neeraj awasthi said:   2 decades ago
If () is not there then int *ptr[] start with [] and it means array of pointers of type integers.

Nagaraj said:   2 decades ago
The below program explains tat the starting address of the array. so it is [int (*ptr)[5];] is a pointer to array not array pointer which can be declared by int *ptr[5];
#include<stdio.h>
int main()
{
int arr[5];
int (*ptr)[5];
ptr=&arr[10];

printf("%ld",ptr[5]);
return 0;
}

Subaidha said:   2 decades ago
* means its represent as a pointer variable and here within a array bracket they give us 10 integers.

So that the ans is B.

Balaji said:   2 decades ago
Can you explain me the concept?

Purna chandra said:   2 decades ago
Yes p is pointer of 10 integers.

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

LOL said:   1 decade ago
The brackets are the key to this problem. Always read C declarations from right to left (backwards) and start will stuff inside brackets.

[] = array * = pointer

int *ptr [10] backwards is [10] ptr * int

so this is Array of 10 pointers to int

int (*ptr)[10] bracket first and backwards is * ptr [10] int

so this is pointer to an array of 10 integers

Chris 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;
}

// Ans : 4 5 5 4 5

Can any one explain the above code please ?

Sagar Said said:   2 decades ago
Can you explain me the concept


Post your comments here:

Your comments will be displayed after verification.