pointers

sorting the linked list

I am trying to make a function that sorts the linked list,which sorts the list by names. struct student { char name[50]; int roll_no; struct student *ptr_next; }*ptr_this,*ptr_first;/*ptr first points to first pointer */ void SortRecord(void) { struct student *out,*in,*temp; for(out=ptr_first;out!=(struct student*)NULL;out=out...

What's a canonical example of code kata to learn about pointers ?

I've never worked with a language that didn't provide for some form of memory management, and thus managed to get by without ever really groking pointers. I can dabble in C I guess, as a result of coding in Objective-C for a little while. ...

declaring a pointer to a two dimension array of void*

I'm having trouble figuring out how to declare a pointer to an array of arrays of void*. (I can't use STL containers and the like because it's an embedded system.) I have some data that I'm trying to group together in a structure. Mostly built-in data types, but then are these two arrays. The first one, char *testpanel_desc[] = {...}; ...

C++ Pointer Question

Hello, I apologize since this is rather a n00bish question, but I can't figure this one out. class View //simplified { public: ROILine* ROI() {return _roi;} //setter does some control stuff... private: ROILine *_roi; } class ROI : public eq::Object { public: //virtual ROI(ROI* copy) = 0; virtual ~ROI() {}; virtual ui...

C++: how to access a multidimensional array with pointers?

Given: (In C++) int main () { int* ptr; int ary [10][2]; ptr = ary; return 0; } How would I access ary[0][1] with ptr? ...

Difference between the int * i and int** i

What is the difference between int* i and int** i? ...

How to overwrite pointer assoziation in php? Or how to operate on arrays with n dimensions?

Hi, I have a nasty little problem with the pointer opperator in php (&). I want to loop through a while loop, which writes data in an array. Each time it is supposed to write into the next dimension of the array (1st in $array, then in $array[0], then in array[0][0], etc). I wanted to do this by linking to $array with a pointer, then ch...

[DELPHI] Array of procedures inside a class pointing to class method

Hello. I have a class (TExample) and I want to have an array of pointers that point to TExample methods. For example, I'd like to have TExample.ThinkOne and do aPointers[1] := @TExample.ThinkOne or something similar. How can I properly do this? Thanks. ...

Pointers vs auto_ptr vs shared_ptr

I was recently introduced to the existence of auto_ptr and shared_ptr and I have a pretty simple/naive question. I try to implement a data structure and I need to point to the children of a Node which (are more than 1 and its) number may change. Which is the best alternative and why: class Node { public: // ... Node...

C++ Passing Pointer to Function (Howto) + C++ Pointer Manipulation

I am a little confused as to how passing pointers works. Let's say I have the following function and pointer, and... EDIT: ...I want to use a pointer to some object as an argument in the function. i.e.: void Fun(int Pointer){ int Fun_Ptr = ---Passed Pointer---; //So that Fun_Ptr points to whatever ---Passed Pointer points...

Printing char pointer in C - I keep getting bad formatting

I am reading a line from a file containing the names of people, first line contains names of males, and seconds line contains names of females. Then I want to store these names in two arrays, one for males, one for females, however when I print them I get weird things. I'm not sure if I am not reading them correctly, or printing them inc...

C++: Container of original pointers

Hello folks, I need to store references to instances of derived classes in C++. I considered using a vector of shared_ptrs to the base class (for it needs to hold different types of derived classes), however, it's important that the container holds the original pointers, which is not the case with vectors (or other stl containers), if I...

Restricted pointer questions

I'm a little confused about the rules regarding restricted pointers. Maybe someone out there can help me out. Is it legal to define nested restricted pointers as follows: int* restrict a; int* restrict b; a = malloc(sizeof(int)); // b = a; <-- assignment here is illegal, needs to happen in child block // *b = rand(); while(1) {...

difference between static_cast<const A>(*this) and static_cast<const A&>(*this)

in the following code ( taken from effective C++ ): class A { .... .... .... char& operator[](std::size_t position) // now just calls const op[] { return const_cast<char&>( // cast away const on // op[]'s return type; static_ca...

Returning an argument pointer to an object

In C++ for Windows, I have some object factory that is supposed to create a series of Info object by passing a pointer to the object to a Create function and returning a created object. void CreateInfoObject(AbstractInfo** info); // The creation function AbstractInfo is a base class of which we have many types of Info objects derive...

Restricted pointer assignments

I have a question regarding restricted pointer assignments. See the comments in code for specific questions. Overall, I'm just wondering what's legal with restrict (I've read the standard, but still have questions :-( int* Q = malloc(sizeof(int)*100); { int* restrict R = Q; for(int j = 0; j < rand()%50; j++) { R[...

Odd one: @myRecordArray[0] returns invalid pointer if array size is bigger than 4136

hello stack, this is really strange, i have an array in delphi and fill it with directX matrices. then i get the pointer to the first element and pass it via com to c# managed code: function TMPlugTransformInPin.GetMatrixPointer(out SliceCount: Integer; out ValueP: Int64): HResult; var matrices: array of TD3DMatrix; i: Integer;...

Delete parts of a dynamic array and grow other

I need to have a dynamic array, so I need to allocate the necessary amount of memory through a pointer. What makes me wonder about which is a good solution, is that C++ has the ability to do something like: int * p = new int[6]; which allocates the necessary array. What I need is that, afterwards, I want to grow some parts of this arr...

I need a container that supports efficient random access and O(k) insertion and removal

I have tried again to ask the same question, but I ended up asking a different question by not providing essential information about my problem. I implement a data structure which is a tree. Each node of this tree has an array/vector/(random access structure) with all its children which can be arbitrary many. The insertion/removal of el...

What is the difference between sizeof(int) and sizeof(int*)? Also Is this statement int* numbers[] = {....} correct?

Suppose, int numbers [20]; int * p; I think this is statement is valid p = numbers; But this is not numbers = p; Because numbers is an array, operates as a constant pointer, and we cannot assign values to constants. So if we go by this then we cannot use *numbers while initializing the array? ...