Questions tagged [pointer-to-array]
56 questions
1
vote
2 answers
What value does a pointer to pointer get assigned when points to a dynamically allocated memory?
Consider the following case:
int **my_array = new int*[10];
What do we assign to my_array here?
my_array is a pointer that points to what?
Is there any way to iterate through my_array (the pointer) and set up a two-dimensional array of integers…

user5241471
- 105
- 5
1
vote
4 answers
Check the following code. Its related to the pointer to an array concept
Consider the following code
#include
void main()
{
int s[4][2] =
{
{20,1},
{21,2},
{22,3},
{23,5}
};
int (*p)[2];
int i,j,*pint;
for( i=0;i<=3;i++)
{
p=&s[i];
…

Blessen George
- 270
- 3
- 18
1
vote
2 answers
Structure within pointers of the same type of structure
typedef struct roads road;
typedef struct city city;
I am implementing a code that has a road, two cities on its edges, I will read them from a file and make them linked. Structure is like
NewYork 250km LosAngeles
LosAngeles 120km …

Karavana
- 489
- 5
- 19
0
votes
2 answers
Evaluation order of &a[0]
Assume one dimensional array a={1,2,3,4} with base address as 100.Find the value of p.
P=&a[0];
I know it will give tha base address of 0th element of 1D array. But in which order c compiler will evaluate this in first way or…

Roshan Rai
- 11
- 2
0
votes
0 answers
How to get values from aggregation cursor which is not an array Nodejs Mongodb
I have an aggregation like this :
this.collection.aggregate([
{
"$match": {
_id: id
}
},
{
"$addFields": {
"self": "$$ROOT"
}
},
{
"$graphLookup": {
…

Sara
- 5
- 3
0
votes
2 answers
Pointer-to-array, malloc, and out-of-bounds access
Given a pointer-to-array in C, can we malloc to it enough memory for extra elements (beyond the specified array size) and then safely access those elements using either the [] operator or pointer arithmetic?
Consider this example:
int (*foo)[ 10 ];…

Jackson Allan
- 727
- 3
- 11
0
votes
1 answer
How to deal with undefined behavior of pointer to array in cpp?
I was learning about pointers and pointers to arrays, when I encountered this strange thing.
Can anyone explain why this works?
char str[] = "This is a String";
int *p = str;
while(*p) std::cout<<*p++;
and returns :
but this one generates a nasty…

Vjkaal
- 3
- 4
0
votes
2 answers
How can you dynamically allocate a pointer in the form int (*p)[n] in C?
Suppose I get input from somewhere and store it in a variable. Pretend the variable is Cols.
I want to make an array in the form
int (*p)[Cols]
Now, I know you can't do this. So how would I dynamically allocate it to do it?
Teaching me how to do so…

V_S
- 27
- 6
0
votes
1 answer
difference between (*)[] and * in C
would love for some help with understanding the difference between these two lines:
int(*p)[20] = (int(*)[20]) malloc(sizeof(int) * 20);
int* y = (int*)malloc(sizeof(int) * 20);
if I do:
int * tmp = p;
OR
int * tmp = y;
I get the address of the…

Roe
- 61
- 1
- 3
0
votes
2 answers
Ommiting second dimension for 2-d array in formal argument doesn't throw any error or warning
I was going through the answers to this question Why is it allowed to omit the first dimension, but not the other dimensions when declaring a multi-dimensonal array? and some other questions as well and I understood that we can omit the first…

Vinay Yadav
- 1,206
- 1
- 10
- 19
0
votes
1 answer
Using strings or pointers to strings in struct
I think I am missing something critical and I can't find an answer. If I want to use string in struct, is it better to use char arrays or pointers to them?
Following code works as intended, but raises warnings
"Warning C4047 'function': 'const…

Swajn
- 1
0
votes
1 answer
How does a pointer to a 2D array work underneath the hood?
I can't understand why this piece of code which is supposed to perform matrix multiplication goes wrong.
Input: 2x2 matrices with elements 1,2,3,4 in both matrices
Expected output: 7 10 15 22
Output given by this code: 15 22 12 16
int a[10][10],…

Manogyana T
- 31
- 5
0
votes
1 answer
Pointers to Pointers to Avoid Duplicate Code?
I am new to learning about C, so as an exercise I attempted to create a text-based card game where each person/CPU places down a random card at the top of their deck, and the person with the higher card will take the card and add it to their deck. …

iRove
- 562
- 1
- 9
- 19
0
votes
2 answers
Pointer to pointer Array
I am trying to make an 'int** arr[5]' the each cell in it contains an 'int* array', each 'int* array' has a different size. Whenever i am trying to print one of the cell it prints only the first number in it, why is it happening? how can i print the…

Yazen Vid
- 21
- 3
0
votes
1 answer
Passing pointer-to-char in function: syntax error
My question is related to my previous post:
explicit specialization: syntax error?
I am trying to pass arrays of pointer-to-chars as an argument to a function (which I will later incorporate to a specialized function from previous post), but I…

mi5tch
- 1
- 2