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 2 of 7.
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.
Nagaraj said:
1 decade 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;
}
#include<stdio.h>
int main()
{
int arr[5];
int (*ptr)[5];
ptr=&arr[10];
printf("%ld",ptr[5]);
return 0;
}
Padmanaban said:
1 decade ago
I have got that ++a is pre-increment so it will increment and then assign the value.
Similarly a++ means it assigns and then increment so its value cannot be printed by this only it shows the value what we assigned..... clear per-increment post-increment is the concept used there...!!!!!
Similarly a++ means it assigns and then increment so its value cannot be printed by this only it shows the value what we assigned..... clear per-increment post-increment is the concept used there...!!!!!
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".
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".
Bhuvi said:
8 years ago
@ALL.
#include<stdio.h>
int main()
{
int a=5;
printf("%d %d %d %d %d", a++, a--, ++a, --a, a);
return 0;
}
This depends on the compiler, we don't know the order in which this expression is evaluated is either right to left or left to right.
#include<stdio.h>
int main()
{
int a=5;
printf("%d %d %d %d %d", a++, a--, ++a, --a, a);
return 0;
}
This depends on the compiler, we don't know the order in which this expression is evaluated is either right to left or left to right.
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\'
{
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\'
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.....
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.....
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.
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)
Abhishek prajapati said:
6 years ago
As we write ' int a[10] ' then we call it:- a is an array of 10 integer type elements.
Like that we can say in " int (*ptr)[10] "ptr (due to * ptr is pointer variable) is a pointer to an array of 10 integer type elements.
Like that we can say in " int (*ptr)[10] "ptr (due to * ptr is pointer variable) is a pointer to an array of 10 integer type elements.
(1)
Sirish said:
2 years ago
Here, we can observe there is no comma operator ( (*ptr) , [10]) so, we can identify what's the array name, because the array name must be declared. So, *ptr=a, then the array becomes a[10], 10 elements are there in the array "a".
(6)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers