Questions tagged [pointer-to-array]

56 questions
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[…
radu-matei
  • 3,469
  • 1
  • 29
  • 47
2
votes
3 answers

Why should we use pointer-to-arrays in C/C++?

#include #define SIZE 3 int main() { char intArrayOne[SIZE] = {'A', 'B', 'C'}; char (*ptrToAnOneDimArray)[SIZE] = &intArrayOne; int i = 0; for(i=0 ; i
user366312
  • 16,949
  • 65
  • 235
  • 452
2
votes
4 answers

How to populate 2d array with random numbers using pointers

When I execute this code, I don't get a matrix of completely random numbers but instead get many repeating numbers. Any idea how I can rainGen function to produce a truly random 2d matrix? Any help you can provide would be really really…
2
votes
3 answers

How can I pass a multidimensional array as a pointer in c

Possible Duplicate: How to pass a multidimensional array to a function in C and C++ so I have char buffer[4][50] I need to pass it to a method void SetBuffer(char **buffer) or at least that's how i think it's suppose to be formatted. so I do…
Pittfall
  • 2,751
  • 6
  • 32
  • 61
1
vote
3 answers

Warnings of Pointer to array of matrices In ANSI C GCC C90

I'm having strange warnings in Linux. In Visual Studio on Windows, the code compiles and works well but I need to compile it with GCC c90 I get these warnings: I've initialized the matrix like this: typedef float mat[4][4]; Now i want to create an…
1
vote
1 answer

Pointers to arrays and effective types

I’m confused about effective type in the case of pointers to arrays in C. Does accessing an individual member via a pointer to an array impart an effective type only on the memory for that member or across all the memory encompassed by the array? Is…
Jackson Allan
  • 727
  • 3
  • 11
1
vote
2 answers

What is the difference between int (*p)[10]=s and int (*o)[5]=&s?

On basis of the convention int (*o)[5]=&s; is the right way for a pointer o to point an array having 5 elements. We can also write this s in this statement int (*p)[10]=s; but why preferring &s at int (*o)[5]=&s; as both of them return the same…
1
vote
2 answers

Modifying elements of an array through a pointer to its elements

Given the code: int vector[5] = {1, 2, 3, 4, 5}; int *pv = vector, value = 3; for(int i = 0; i < 5; i++) { *pv++ *= value; } for(int i = 0; i < 5; i++) { printf("%d, ", *(pv+i)); } I expect each individual element of the array pointed to…
1
vote
3 answers

Why does the declaration int (*f())[]; doesn't give an error or warning?

The following statement declares a function which takes no argument and returns a pointer to an integer array. int (*f())[]; It returns a pointer to an integer array of size _____ We didn't specify the size of the array, so it should give some kind…
Vinay Yadav
  • 1,206
  • 1
  • 10
  • 19
1
vote
2 answers

confused about pointer syntax when defining type in C

In some starter code we have: /** * RGBTRIPLE * * This structure describes a color consisting of relative intensities of * red, green, and blue. * * Adapted from http://msdn.microsoft.com/en-us/library/aa922590.aspx. */ typedef struct { …
DCR
  • 14,737
  • 12
  • 52
  • 115
1
vote
1 answer

Pointer to array of runtime-determined size pre-C99

Before C99, does the C standard allow defining or casting to pointers to arrays of length determined at runtime? I understand that the standard doesn't allow variable length arrays before C99, but whether pointers to arrays of runtime-determined…
Puk
  • 225
  • 2
  • 7
1
vote
2 answers

How could I swap rows in a 2D array defined using pointers to array?

I want to swap two rows of a 2d array defined as bellow. double (*mat)[N]; mat = (double(*)[N])malloc(m*sizeof(double [N])); ... swap(mat, mat+1); But my swap(mat, mat+1); only swaps the first element in each row. void swap(double…
1
vote
3 answers

Array and Array[0] confusion

In the following C code: char test[] ={'T','e','s','t'}; printf("%d\n",test == &test[0]); // Returns 1 - Okay as array varaible holds address of first element So shouldn't the following should print the same?: printf("value of test %c\n", test);…
lynxx
  • 544
  • 3
  • 18
1
vote
2 answers

C++ Getting neighbours of a cell in a grid, -1x throwing null exception when checked if != NULL

recently moved from C# to C++ so I'm new to pointers and references and so on. I've a pointer-to-pointer array declared like this enum Type { Void, DeepWater, Water, ... etc } Tile::Type** tiles; TileManager::TileManager(int width,…
Anthony
  • 301
  • 1
  • 2
  • 13
1
vote
1 answer

Function with a pointer to an array argument in C

I have written code below that contains a function with a pointer to a double array of size 3.My problems is this: when I pass the address of pointer to a double variable (that clearly isn't an array) and then want to change the value of this double…
Mehdi
  • 47
  • 5