Questions tagged [pointer-to-array]
51 questions
8
votes
3 answers
Using and dereferencing (void**)
I would like to pass a "polymorphic" array of pointers to a function.
I can do the following without warnings:
foo (void* ptr);
bar()
{
int* x;
...
foo(x);
}
gcc apparently automatically casts x to a (void*), which is just dandy.
However, I…
![](../../users/profiles/925978.webp)
crockeea
- 21,467
- 10
- 44
- 93
7
votes
5 answers
What is a pointer to array, int (*ptr)[10], and how does it work?
int (*ptr)[10];
I was expecting ptr to be an array of pointers of 10 integers.
I'm not understanding how it is a pointer to an array of 10 integers.
![](../../users/profiles/13917137.webp)
rahulvuppala v
- 81
- 3
7
votes
2 answers
How to get size of 2D array pointed by a double pointer?
I am trying to get the number of rows and columns of a 2D Array from a double pointer pointed to the array.
#include
#include
void get_details(int **a)
{
int row = ??? // how get no. of rows
int column = ??? // how…
![](../../users/profiles/1757839.webp)
Yash
- 83
- 1
- 2
- 4
4
votes
3 answers
Why is the result of using `int (*p)[5]` so confusing?
I know that int (*p)[5] means a pointer which points to an array of 5 ints.
So I code this program below:
#include
using namespace std;
int main()
{
int a[5]={0,1,2,3,4};
int (*q)[5]=&a;
cout<
![](../../users/profiles/964314.webp)
Archeosudoerus
- 1,091
- 9
- 23
4
votes
3 answers
If int (*p_arr)[10] is defined as a pointer to an array of size 10 then why compiler shows warning in this case?
I have this code:
#include
int main()
{
int arr[10] = {0};
int *p1_arr = arr;
int (*p2_arr)[10] = arr; // Line 7, Shows Warning here
...
return 0;
}
On compiling on gcc using gcc -g -Wall LengthofArray.c, it…
![](../../users/profiles/2628863.webp)
Don't You Worry Child
- 5,726
- 2
- 22
- 47
3
votes
0 answers
GDB misses to display const qualifier?
Give the following source (main.c):
void foo(const char (*pa)[4])
{
}
int main(void)
{
const char a[4] = "bar";
foo(&a);
}
... compiled with GCC (gcc (Debian 4.9.2-10) 4.9.2) and run under GDB (GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1) ...
(gdb) b…
![](../../users/profiles/694576.webp)
alk
- 66,653
- 10
- 83
- 219
3
votes
1 answer
Array pointer in C program
Here is a C program in textbook, it asks a 3*5 2D array from users and prints the third line.
I am confused with int* p[5]. Why here needs to have [5], I think just int* p is OK. It can repeatedly add and point to the next memory space in the int…
![](../../users/profiles/6079614.webp)
Jennifer Q
- 237
- 3
- 12
3
votes
1 answer
Pointer to array and errors C2057, C2540
I want to do something like:
const int N = 10;
void foo (const int count)
{
int (* pA) [N][count] = reinterpret_cast(new int[N * count]);
...
}
But my compiler (VS2010) doesn't want to do it:
error C2057: expected constant…
![](../../users/profiles/3241228.webp)
user1234567
- 2,779
- 2
- 16
- 20
2
votes
1 answer
Initializing pointer to array without & operator?
In the following pointer to array,
int x[5] = {1};
int (*a)[5] = &x;
what implications and consequences can i have if i don't use & operator and do like this..
int x[5] = {1};
int (*a)[5] = x; //No & operator
Can anyone explain with some good…
![](../../users/profiles/9715763.webp)
Armaan Saxena
- 31
- 4
2
votes
2 answers
How to define and use a pointer to an "array" member?
I have a bunch of structs, each of which has an 'array' member and a size indicator:
struct S {
size_t num;
int arr[100];
};
struct V {
float array[10];
int size;
};
I want to create manipulator objects for each struct:
template…
![](../../users/profiles/92318.webp)
Benji Mizrahi
- 2,044
- 1
- 23
- 34
2
votes
3 answers
How to use pointer to multi dimentional array in C language?
I have 2-D array
char arr[2][3]={"sam","ali"}
and pointer to this array
char(*ptr)[3]=arr;
How can I use this pointer to print arr[2][2] which in this case is i.
I've tried * (*(ptr+1)+2) the same way I am dealing with the array but didn't work so…
![](../../users/profiles/8002691.webp)
Mohamed Moustafa
- 87
- 7
2
votes
2 answers
While dereferencing pointer to an array I am getting same address as that of pointer to an array
#include
int main(void)
{
int arr[5]={1,2,3,4,5};
int (*ptr)[5]=&arr;
printf("ptr=%p\n",ptr); i am not getting the diff btw both statements
printf("*ptr=%p\n",*ptr);
return 0;
}
output:-…
![](../../users/profiles/7338097.webp)
sam1006
- 83
- 1
- 8
2
votes
0 answers
Array of Pointers to 2d Arrays
I have 5 different 2d Arrays in contrast to the normal usage of 2d Arrays.
int A[1][2] = {2, 5};
int B[1][2] = {6, 1};
int C[1][2] = {4, 8};
int D[1][2] = {3, 6};
int E[1][2] = {9, 7};
Then I have declared an array of Pointers to these 5 arrays by:…
![](../../users/profiles/1900929.webp)
Mohammad Sohaib
- 547
- 3
- 9
- 24
2
votes
6 answers
How is pointer to array different from array names?
I was reading more about arrays vs pointers in C and wrote the following program.
#include
int arr[10] = { } ;
typedef int (*type)[10] ;
int main()
{
type val = &arr ;
printf("Size is %lu\n", sizeof(val)) ;
printf("Size of…
![](../../users/profiles/2790036.webp)
Pratik Singhal
- 5,566
- 7
- 48
- 88
2
votes
1 answer
How to make a pointer to a vector? I work on a vector inside the function and I want to keep the values
I am writing a C function so that when called, the function would return an array (vector) of the first p prime numbers(with p given from the keyboard in main).
My problem is when I try to call the function in main.
void vector_prime(int p, int *v[…
![](../../users/profiles/3084239.webp)
radu-matei
- 3,323
- 1
- 26
- 45