250 questions
1
vote
3
answers
1k
views
Pass stream by reference
I am suppose to pass stream, which is a pointer, by reference. So I am passing this as a pointer to a pointer. Can someone please verify my code?
int main(int argc, char** argv)
{
FILE *...
1
vote
0
answers
782
views
Python ctypes - Passing a pointer to a pointer
I have a DLL with a function of the following form:
void Foo ( int * i, char ** s )
{
if ( *i > (int)(strlen(date_string) + strlen(time_string) + 2) )
sprintf ( *s, "%s %s", time_string, ...
3
votes
2
answers
276
views
Can I store a reference to a local reference?
To be clear, I want the behavior of a pointer-to-a-pointer, and the purpose of this question is to generate clean, readable code.
I have some code that contains conditions checking the result of ...
-4
votes
2
answers
81
views
If I define a pointer pointing to a smart pointer, does this eliminate the advantages of smart pointer?
C++ smart pointer: if in a class, I define a pointer pointing to a smart pointer, does this eliminate the advantages of smart pointer? (Note, I didn't say I want to apply this kind of usage)
Like:
...
3
votes
7
answers
107
views
What value does a Pointer to a Pointer print if not a single dereference operator is used at all?
I have tried the output of the following code. But, i don't yet understand what might the value of q represent.
I understand that the *q points to p implying that, printing *q would print the address ...
0
votes
1
answer
157
views
realloc in recursion in trees
I am trying to find the maximum sum leaf to root path in a Binary Tree as in below
http://www.geeksforgeeks.org/find-the-maximum-sum-path-in-a-binary-tree/
1) I am unable to find why the path doesn't ...
1
vote
2
answers
164
views
Difference between the address of the variable that points to an array and the value of that variable itself
I have an array
int ar[5] = {1,2,3,4,5};
printf("%d",(ar==&ar));
The print statement returns true. But what if I do ar+1 and &ar+1. Where does that point to?
Also if I have
char *c[] = {"...
0
votes
5
answers
330
views
Is this pointer to pointer redundant?
Code is like this:
void insertNode(TreeNode **root, COMPARE compare, void* data) {
TreeNode *node = (TreeNode *)malloc(sizeof(TreeNode));
node->data = data;
node->left = NULL;
...
0
votes
1
answer
802
views
invalid conversion from 'class**' to 'base class**' [duplicate]
I want to pass a pointer of pointer of object to a function but get the error
invalid conversion from 'CustomInterface**' to LocalLogger**'
I try something like this:
class LocalLogger
{}
class ...
0
votes
1
answer
72
views
Error when working with pointer to a pointer in Binary Search Tree functionality
I've got the following code:
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
struct Node
{
int value;
Node *left, *right;...
0
votes
2
answers
46
views
PointerToPointer : How to return the modified values/structure back to the original list?
While writing the add function for Linked List I came up with the following piece of code
int addNode(node ** head)
{
1. node * ptr = *head;
if(ptr==NULL)
{
...
1
vote
2
answers
5k
views
Declaration and initialize pointer-to-pointer char-array
Concerning a pointer to pointer I wonder if its ok with the following:
char** _charPp = new char*[10];
for (int i = 0; i < 10; i++)
´ _charPp[i] = new char[100];
That is - if I ...
-1
votes
1
answer
223
views
Depth first search & breafth first search implementation in C++
I am a beginning level coder, and am coding dfs bfs, bt its reapetedly showing error,I have assigned an array of nodes for wich i have used pointer to pointer, however when i assign values to elements ...
0
votes
0
answers
115
views
Void pointer to struct pointers.Prob when putting the address in the void pointer
I got a void **stack which contains the addresses of the struct pointers
my problem is that when I print the whole stack different addresses are shown than the actual addresses I'm actually trying to ...
0
votes
2
answers
12k
views
Compiler error (lvalue required as left operand of assignment) when using malloc
I got 2 structs,a pointer to each struct and a void **stack which points to the pointers of the structs.
my problem is at the line
(*ptr2+*a)=(struct student *)malloc(sizeof(struct student));
*a is ...
0
votes
2
answers
80
views
When I try to run it the program crashes and I don't know why
I want to return in my function the n - size of the matrix - and the matrix itself at *p.
The file is something like, for example,
3
10
20
30
this is how I call it:
main( )
{
...
2
votes
1
answer
4k
views
Double and triple pointers in C
I have a small program as shown below.This program is an attempt to better understand pointers in 'C' how variables are arranged in memory.
#include <stdio.h>
const char *c = "hello";
const ...
2
votes
3
answers
13k
views
How can a double pointer be used for a two dimensional matrix?
I am trying my hand at C by implementing Conway's game of Life.
I am trying to dynamically build two grids (int matrices), one for the current and one for the next generation, so after I determine ...
1
vote
1
answer
322
views
double pointer that is passed gets corrupted during loops?
char **rhyme; // init my double pointer
rhyme=inputrhyme(); // calls below function to input the rhyme
char** inputrhyme(){
char **rhyme, *temp, *token, BUFF[300], s[2]=" ";
int length=0;
...
2
votes
1
answer
282
views
Initializing and Navigating a char**
Okay, so consider this code:
char** pool = new char*[2];
pool[0] = new char[sizeof(char)*5];
As far as I know, this creates a pointer to an array of 2 char pointers. The second line then sets the ...
0
votes
0
answers
103
views
Address of pointer throws a segfault in C++
I have a function that is supposed to return a double pointer, it is supposed to return the address of the pointer to a piece of data which in this example is a character array
The original data is ...
0
votes
1
answer
97
views
Double pointer to 2D
I have an an integer array of values and I would like to make a double pointer to point to this array. I assume that this 1D integer array actually represents a 2D array. That is for instance that if ...
6
votes
7
answers
3k
views
Why should I use double pointer variable to receive another pointer's address(&ptr1)
int num = 45,*ptr1,*ptr2;
ptr1=#
ptr2=&ptr1;
printf("%d\n",*ptr1);
I've been thinking about this question for a while, but couldn't find a way to understand it,why &ptr1 can not be ...
6
votes
2
answers
4k
views
Multi-dimensional array and pointer to pointers
When you create the multi-dimensional array char a[10][10], according to my book it says you must use a parameter similar to char a[][10] to pass the array to a function.
Why must you specify the ...
2
votes
6
answers
2k
views
How many consecutive nested pointer (pointer to pointer) can i have in one order? Is there a limit of doing references?
The follow program declares a pointer then again a new pointer to hold address of previous pointer variable.. How much can I use nested pointer variable to hold memory address
is there any limit?
#...