pointers

C++ pointer, Beginner Question...

Hi there, just want to ask a beginner question... here, I made some code, for understanding the concept/basic of pointer: int a=1; int *b=&a; int **c = &b; int ***d = &c; cout << &*(&*d) << endl; can someone explain to me, why the &*(&*d) return address of "c" instead of address of "b"? I've also tried code like &*(&*(&*(&*(&*d)))),...

Using `<List>` when dealing with pointers in C#.

How can I add an item to a list if that item is essentially a pointer and avoid changing every item in my list to the newest instance of that item? Here's what I mean: I am doing image processing, and there is a chance that I will need to deal with images that come in faster than I can process (for a short period of time). After this "b...

Pointers in C# to make int array?

The following C++ program compiles and runs as expected: #include <stdio.h> int main(int argc, char* argv[]) { int* test = new int[10]; for (int i = 0; i < 10; i++) test[i] = i * 10; printf("%d \n", test[5]); // 50 printf("%d \n", 5[test]); // 50 return getchar(); } The closest C# simple example I c...

Double indirection and structures passed into a function

I am curious why this code works: typedef struct test_struct { int id; } test_struct; void test_func(test_struct ** my_struct) { test_struct my_test_struct; my_test_struct.id=267; *my_struct = &my_test_struct; } int main () { test_struct * main_struct; test_func(&main_struct); printf("%d\n",main_struct->id); } This works, but...

NSArrays in NSArrays. A pointer problem?

I believe my problem involves pointers, a concept I often struggle with, but here's what I'm trying to do. I have six NSArrays. I want an additional NSArray comprised of these six arrays, so: self.arr1 = [NSArray array]; self.arr2 = [NSArray array]; self.arr3 = [NSArray array]; self.arr4 = [NSArray array]; self.arr5 = [NSArray array]; ...

Array of pointers in objective-c

I'm getting confused by pointers in objective-c. Basically I have a bunch of static data in my code. static int dataSet0[2][2] = {{0, 1}, {2, 3}}; static int dataSet1[2][2] = {{4, 5}, {6, 7}}; And I want to have an array to index it all. dataSets[0]; //Would give me dataSet0... What should the type of dataSets be, and how would I...

How to store a function pointer in C#

Let's say I want to store a group of function pointers in a List<(*func)>, and then later call them, perhaps even with parameters... Like if I stored in a Dict<(*func), object[] params> could I call the func with the parameters? How would I do this? ...

Strange code behaviour?

I have a C code in which I have a structure declaration which has an array of int[576] declared in it. For some reason, i had to remove this array from the structure, So I replaced this array with a pointer as int *ptr; declared some global array of same type, somewhere else in the code, and initialized this pointer by assigning the glo...

function pointer error

Can anybody help me with this simple code?? #include <iostream> using namespace std; void testFunction(){ cout<<"This is the test function 0"<<endl; } void testFunction1(){ cout<<"This is the test function 1"<<endl; } void testFunction2(){ cout<<"This is the test function 2"<<endl; } void (*fp[])()={testFunction,testFunc...

handling refrence to pointers/double pointers using SWIG [C++ to Java]

My code has an interface like class IExample { ~IExample(); //pure virtual methods ...}; a class inheriting the interface like class CExample : public IExample { protected: CExample(); //implementation of pure virtual methods ... }; and a global function to create object of this class - createExample( IExample *& obj ) { obj = new ...

How to check if memory has been initialized?

Is there a way of checking if memory pointed to by pointer has been initialized?(not necessarily by my program). Thanks ...

Sort a list of pointers.

Hello all, Once again I find myself failing at some really simple task in C++. Sometimes I wish I could de-learn all I know from OO in java, since my problems usually start by thinking like Java. Anyways, I have a std::list<BaseObject*> that I want to sort. Let's say that BaseObject is: class BaseObject { protected: int id; public...

Question on Pointer Arithmetic

Heyy Everybody! I am trying to create a memory management system, so that a user can call myMalloc, a method I created. I have a linked list keeping track of my free memory. My problem is when I am attempting to find the end of a free bit in my linked list. I am attempting to add the size of the memory free in that section (which is i...

Accessing structure through pointers [c]

I've got a structure which holds names and ages. I've made a linked-list of these structures, using this as a pointer: aNode *rootA; in my main. Now i send **rootA to a function like so addElement(5,"Drew",&rootA); Because i need to pass rootA by reference so that I can edit it in other functions (in my actual program i have two r...

Purpose of dereferencing a pointer as a parameter in C.

I recently came along this line of code: CustomData_em_free_block(&em->vdata, &eve->data); And I thought, isn't: a->b just syntactic sugar for: (*a).b With that in mind, this line could be re-written as: CustomData_em_free_block(&(*em).vdata, &(*eve).data); If that's the case, what is the point of passing in &(*a), as a para...

Can memory be leaked when using vector of pointer in c++?

I tried this: .... vector<players*> player; for (int i = 0; i<10; i++) { player.push_back(new players()); } ... And I wonder if I need to free memory for the vector? If so, how? ...

dangling pointer, reason for value change after free()?

In the following code segment, after free(x), why does y becomes 0? As per my understanding, the memory in the heap that was being pointed to by x, and is still being pointed by y, hasn't been allocated to someone else, so how can it change to 0? And moreover, I don't think it is free(x) that changed it to 0. Any comments? #include <...

Cannot take the address of, get the size of, or declare a pointer to a managed type ('type name')

this error stops compiling if i have one or more System.String in my structs is there any other way to store strings? i have tried things like this: private long _B_ID; private byte[] _C_Name; private byte[] _C_Address; private byte[] _C_Telephone; but it is not seeming to work. ...

How are arrays passed?

Are arrays passed by default by ref or value? Thanks. ...

pointers in structs a memory leak?

I couldn't find any mention of this online... wouldn't putting a pointer in a struct be a bad thing? (at least in the modern object oriented programing) The programmer would inevitably creating a memory leak correct? (unless they, every time they use it, they disassociate the memory every time) Assuming that the above is correct... is i...