C Programming - Arrays - Discussion
Discussion Forum : Arrays - General Questions (Q.No. 2)
2.
What does the following declaration mean?
int (*ptr)[10];
int (*ptr)[10];
Discussion:
64 comments Page 4 of 7.
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.
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.
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.
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.
This array would be accessed by that pointer.
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.
Sasi said:
1 decade ago
int (*ptr) [10].
We can take this a cyclic check and everyone can read it easily by this way.
Start with ptr as it is a pointer go clock wise the next comes as array of size 10 that means ptr is a pointer to an array of 10 and the return type is int so it is finally as:.
ptr is a pointer to an array of 10 integers.
We can take this a cyclic check and everyone can read it easily by this way.
Start with ptr as it is a pointer go clock wise the next comes as array of size 10 that means ptr is a pointer to an array of 10 and the return type is int so it is finally as:.
ptr is a pointer to an array of 10 integers.
Vishwaschaurasiya said:
1 decade ago
int (*ptr)[10];
ptr is a pointer, but this declaration is called pointer of an array..
Since,(*) this is unary oprator,known as (Astrick);
ptr is a pointer, but this declaration is called pointer of an array..
Since,(*) this is unary oprator,known as (Astrick);
Goyal said:
1 decade ago
int(*ptr)[10]
Divya said:
1 decade ago
int (*ptr)[10];
Start reading what ever is in brackets 1st ,(ptr is a pointer)
Then go towards left till you hit ; (to an array of 10)
Then go backwards and read what ever is left out, (integers).
Start reading what ever is in brackets 1st ,(ptr is a pointer)
Then go towards left till you hit ; (to an array of 10)
Then go backwards and read what ever is left out, (integers).
Gaurav said:
1 decade ago
int (*arr)[10] /* It refers that arr is a pointer to an array of 10 integers*/
and,
int *arr[10] refers to an array of pointers which can hold the starting address of 10 different array of integer data type....
and,
int *arr[10] refers to an array of pointers which can hold the starting address of 10 different array of integer data type....
Nitin Goyal said:
1 decade ago
Here ptr is the pointer for the memory location occupied by array having 10 elements.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers