Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Search the Tips
Tip Bank > C++ > Pointer Arithmetic

Pointer Arithmetic - Page 2

21-40 of 79     Previous     Next
Clarifying a Common Source of Pointer Confusion
by Danny Kalev
Novices, especially those who have experience with garbage-collected languages, are often confused with the concept of object deallocation and destruction in C++. They tend to explicitly invoke every ...
Container of Pointers
by Danny Kalev
Many programmers believe that by storing pointers instead of objects in a container, they improve performance. However, they forget that the pointers still refer to existing objects that must be ...
Reference to Pointers
by DevX Pro
When should you use reference to pointers like those found in function arguments (class_name * & )?
Assigning a Specific Address to a Pointer
by DevX Pro
How do I assign a specific address location to a pointer (e.g., If I want *ptr to point to 0x5800FF)?
Assigning a Specified Memory Address to a Pointer
by Danny Kalev
In low-level programming and hardware interfaces, you often need to assign a pointer to a specific physical address. To do that, you have to cast the address value using the reinterpret_cast operator.
OS System Calls
by DevX Pro
How can I pass a member function of a class as a pointer in C (pointer type expected: void *)?
Effects of Operator delete
by DevX Pro
Why, after deleting an object I allocated dynamically, is the pointer still there? What exactly have I deleted and what would happen if I assigned a new value to the pointer without nullifying it first?
Hide Function Pointer Declarations With a typedef
by Danny Kalev
Can you tell what the following declaration ...
'Restrict' Pointers
by Danny Kalev
One of the new features in the recently approved C standard C99, is the restrict pointer qualifier. This qualifier can be applied to a data pointer to indicate that, during the scope of that ...
Assign Zero or NULL to a Pointer
by DevX Pro
To initialize a pointer after deleting it, should I assign a NULL to it or zero? Are they the same in C++? I know strictly speaking, I should assign NULLs to deleted pointers. But the app I work with uses zeros instead. I wonder if I need to change them.
Pointers to Class Member Functions
by DevX Pro
I'm trying to write a program that has a pointer to a private member function of a class. A public member function calls some of the private functions by using this pointer. I'm using a typedef for the pointer. The typedef is: typedef void (pvm_em::*code_ptr)(int,int); where pvm_em is the name of my class. I'm making an array of these pointers as follows: code_ptr instructions[29]; and I'm filling this array by using statements that look like: instructions[1] = &pvm_em::mov; All of the code I've mentioned up to this point seems to work just fine, but I get a compiler error when I use the following line of code: (this.instructions)[opcode](arg1, arg2); I've tried several different ways of writing this line of code (with and without the This pointer and trying to dereference the pointer), but I can't seem to get it to work. I get errors saying I must use the ".*" or "->*" operators. What are these operators, and what is the syntax for using them?
No Member-Function to Pointer-to-Member-Function Conversion
by Danny Kalev
Does you compiler accept the following ...
Pointers to Vectors
by DevX Pro
How do you create an array of pointers to vectors? The different vectors will, eventually, have different lengths.
Pointer to Structure
by DevX Pro
I have a struct: struct mystruct { DWORD dw_Id; }*pMystruct; In the following function I want to pass the address of 'dw_Id' which is a member of mystruct. How do I pass it? If I am passing as- foo(pMystruct->(&dw_Id))//compiler error
Iterators Aren't Pointers
by Danny Kalev
< ...
Using Auto_ptr with Arrays
by DevX Pro
Can auto_ptr be used to hold a pointer to an array of objects? For example: auto_ptr p = new int[10]; When auto_ptr is destroyed, will it call the correct delete: "delete [] p" instead of "delete p"?
The Representation Of Pointers To Members
by Danny Kalev
Although pointers to members behave very much like ordinary pointers, behind the scenes, they are not necessarily represented as pointers. In fact, a single pointer to member usually consists of a ...
Declaring Pointers to Member Functions
by Danny Kalev
Pointers to member functions consists of the member function's return type, the class name followed by ::, the pointer's name, and the function's parameter list. For example, a pointer to a member ...
Declaring Pointers to Data Members
by Danny Kalev
Although the syntax of pointers to members may seem a bit confusing at first, it is consistent and resembles the form of ordinary pointers, with the addition of the class name followed by the ...
Pointer Arithmetic
by DevX Pro
I am a programmer beginning to learn C++. I wrote this chunk of code: ///////////////////////////////////////////////////////////// // Get to do some pointer arithmetic! ///////////////////////////////////////////////////////////// #include #include const char NL = '\n'; const char TB = '\t'; char* ReverseString(char *pStr); void main() { char *str = "This is a wild test string..."; char *ch = &str[0]; for (unsigned i=0;i This code compiles without any error warnings. However, when I execute the code, the program crashes with an Access Violation error. In debugging I found that the offending line is in the ReverseString function, and I encounter the Access Violation error at the following statement: *f = *b; I compiled the same program in C++ Builder 3.0. The program compiled successfully, and on execution it worked perfectly fine. So, the problem lies with Visual C++ 6.0 compiler. Let me provide the system configuration. Platform: Intel Operating System: Windows 2000 RC2 Development Environment: Visual C++ 6.0 Enterprise Edition SP3 Why is this error happening?
21-40 of 79     Previous     Next
Thanks for your registration, follow us on our social networks to keep up-to-date