Skip to main content

All Questions

0 votes
3 answers
123 views

Accessing information on a 2d array with a double pointer in a struct (C)

In trying to understand pointers, I created a M[x][y] array, a pointer to said array *p_M[x] and a pointer to said pointer **d_p_M. The first pointer points to the first element of a row in the array ...
pasty guacamole's user avatar
2 votes
3 answers
158 views

Converting to char*** from char* [2][2]

I have the following variable char* a[2][2] = {{"123", "456"}, {"234", "567"}}; I wanted to refer it using another variable. While the cast works, accessing ...
5reep4thy's user avatar
0 votes
0 answers
63 views

Why do we use a single pointer rather than a double pointer to pass an array to a function? [duplicate]

Why not double pointer to take an array? I'm having a bit of problem understanding why an array isn't passed as a double pointer (a pointer to a pointer) since the array name itself is a pointer (...
Hannibal.Br's user avatar
1 vote
3 answers
63 views

How does this code allocate memory and why does it fail to write to the allocated memory?

Why does the code below compile successfully but fail to write memory other than address 0? (compiled in dev-cpp 6.3) #include <stdio.h> #include <stdlib.h> void alloc_arr(int **d_ptr); ...
minhaz hosen's user avatar
1 vote
1 answer
126 views

Is it better to store a 2D image in a flat array or in an array of arrays?

I have two options. receiving and processing pixel data in a flat array. If I choose it, I have to use single pointer. I have to use this code in every repeated pixel data process. int getIndex(int ...
Ssukdaebat60's user avatar
0 votes
1 answer
56 views

Getting Null iterate through to next element of array using pointers

#import<stdio.h> #import<stdlib.h> typedef struct Video { char *name; int unique_views; } Video; typedef struct Viewer { char *username; Video *watched_videos; int ...
Anshal Antony's user avatar
0 votes
2 answers
530 views

Incompatible pointer type pointer to array and double pointer to array

So i am new to programming and i have this program that i have to write, it has an array of integers and i have to pass it to a function with a pointer and then with a double pointer. After i wrote ...
Cromocon's user avatar
-1 votes
1 answer
56 views

C -- pointers to pointers VERSUS array of pointers

In C, why can't I write: char **expectedPINs01 = { "0", "5", "7", "8", "9" }; Cause I got: warning: initialization of ‘char **’ from incompatible ...
Adam's user avatar
  • 25
0 votes
3 answers
794 views

print each char of string array with double pointer in C++

The program is expected to print each char of the string array. #include <iostream> #include <string> using namespace std; int main() { const char* numbers[10]{"One", "...
Yifangt's user avatar
  • 171
-2 votes
2 answers
473 views

Pointer Pointer leads to Segmentation Fault in C

Why can I create an array of pointers and dereference its (pointer-)elements. int a = 1; int* arr[1]; arr[0] = &a; But cannot do the same with pointer to pointers: int** arr2; arr2[0] = &a; -...
ChiefHan's user avatar
0 votes
1 answer
104 views

C - Writing a struct into a 2D array causes Segmentation Fault

I'm trying to write a program that reads a text file into a 2D array of structs, but trying to put a struct into that array causes the program to crash. Here's the program ppm.c #include "ppm.h&...
Chance Spurgeon-Couraud's user avatar
0 votes
1 answer
180 views

dynamic array of strings, but i get heap corruption detected

I try to make a dynamic array of char pointer, what means does pointers can be a dynamic memory too, so in the code above I try to allocate one size to the array and in him, allocate to the first ...
Artur Karabekov's user avatar
0 votes
1 answer
100 views

Double pointer with array in another function

I have to create a program that has an array of costumers (structs that contain name, code and documentation) and functions to insert, remove and list all of them in order of code. I'm not ...
Pedro R.'s user avatar
1 vote
2 answers
2k views

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::...
Anthony's user avatar
  • 301
2 votes
1 answer
98 views

Logic behind calling function by using "Pointer to a function"

Suppose there is a pointer f declared to some function say int foo(int) as : int (*f)(int)=foo; While mentioning about calling foo() function by using this ponter which is passed as argument to some ...
Avi's user avatar
  • 335

15 30 50 per page