pointers

Assigning a pointer to a array of pointers to char

gcc 4.4.4 c89 #define SIZE 5 char *names[SIZE] = {"peter", "lisa", "simon", "sarah", "julie"}; char *search_names[SIZE] = {0}; size_t i = 0; for(i = 0; i < SIZE; i++ ) { search_names[i] = names[i]++; } for(i = 0; i < SIZE; i++) { printf("name to search for [ %s ]\n", search_names[i]); } I ...

C++: Can't work with simple pointers?

I apologize as this is so simple, I was working with my own XOR swap method and wanted for the heck of it compare the speed difference between reference and pointer use (do not spoil it for me!) My XOR ptr function is as follows: void xorSwapPtr (int *x, int *y) { if (x != y && x && y) { *x ^= *y; *y ^= *x; ...

Const confusion in C++

Possible Duplicate: Why is my return type meaningless? Hi, I'm confused about a particular const conversion. I have something like // Returns a pointer that cannot be modified, // although the value it points to can be modified. double* const foo() { static double bar = 3.14; return &bar; } int main() ...

C++: Updating pointers in deep copy (efficiently)

My question is best illustrated with a code sample, so let's just start off with that: class Game { // All this vector does is establish ownership over the Card objects // It is initialized with data when Game is created and then is never // changed. vector<shared_ptr<Card> > m_cards; // And then we have a bunch of ...

I am trying to create an array of objects inside a header file which is failing (Starting C++ Programmer)

EDITED BELOW FOR UPDATES!!! Thank you for the help, please by all means point out ALL mistakes , I don't care if it sounds rude or mean or whatever, emo junk. Just give it to me straight so I can understand what is going wrong. Hi everyone! I am a rookie C++ programmer trying to learn and gain some IRL exp for C++. I am attempting the...

Where should you place the * when declaring a pointer in C?

Possible Duplicate: Whats your preferred pointer declaration style, and why? Should it be: center: int * number; left: int* number; right: int *number; I see the left one as type centric the right one as variable name centric, and the center one as agnostic, but I'm really not sure. Does one make sense in certain situation...

How can I return an array of strings in an ANSI C program?

How can I return an array of strings in an ANSI C program? For example: #include<stdio.h> #define SIZE 10 char ** ReturnStringArray() { //How to do this? } main() { int i=0; //How to do here??? char str ** = ReturnStringArray(); for(i=0 ; i<SIZE ; i++) { printf("%s", str[i]); } } ...

Order of operations for dereference and bracket-ref in C

If I do *ptr[x], is that equivalent to *(ptr[x]), or (*ptr)[x]? ...

C++ multi-dimensional array initialization

Hey Guys, in C++ I want to initialize a double matrix (2-dimensional double array) like I would normally do without pointers like so: double data[4][4] = { 1.0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 }; However, since I want to return and pass it to functions, I need it as a double** pointer. So, basically I need to initia...

array of pointers to a char array

Hello, gcc 4.4.4 c89 However, I am having a problem trying to display all the animals. I have the following code. I am trying display all the animals in the array. So I have 3 array of pointers to char*. Then an array of pointers to these data sets. I have tried to control the inner loop for checking for a -1 and a NULL for the oute...

What are main difrences between * ^ and & in visual-C++ 2010?

What are main difrences between * ^ and & in visual-C++ 2010? ...

Casting void pointers

I've seen a lot of the following in older C code: type_t *x = (type_t *) malloc(...); What's the point of casting the pointer returned from malloc() since it's void *? Is it because older C compilers didn't support void pointers and malloc() used to return char * instead? ...

Syntax for pointer to portion of multi-dimensional statically-allocated array

Okay, I have a multi-dimensional array which is statically-allocated. I'd very much like to get a pointer to a portion of it and use that pointer to access the rest of it. Basically, I'd like to be able to do something like this: #include <stdio.h> #include <string.h> #define DIM1 4 #define DIM2 4 #define DIM3 8 #define DIM4 64 static...

Multidimensional array of object in C++ , I can not initialize it!

Hi everyone! Rookie C++ Programmer here again I'm using VC++ VS2008 and making an attempt at creating an array of arrays. All objects I wish to store I want to put on the heap. In the arrays it's all just pointers. Here's some code: Grid.h #include "Tile.h" class Grid { public: Tile* grid_ptr[8][8]; ... ... }; Grid.c...

C++: Array of member function pointers to different functions

I have a class A which contains member functions foo() and bar() which both return a pointer to class B. How can I declare an array containing the functions foo and bar as a member variable in class A? And how do I call the functions through the array? ...

return from incompatible pointer types

The below code generates the incompatible pointer type error: char *PLURAL(int objects, NSString *singluar, NSString *pluralised) { return objects ==1 ? singluar:pluralised;} I am new to objective-C and programming in general so can some one help me with this error? ...

Can we say "passing a function pointer as an argument to a function is called as callback function"?

Can we say "passing a function pointer as an argument to a function is called as callback function"? ...

testing for valid pointer in c++

I wrote a little test to check for null pointer, I simplified it with int and 0, 1, instead of real classes, what I'm trying to test is something like this: return p ? 1 : 0; which in real world would be return p ? p->callmethod() : 0; bool TestTrueFalse(); void main() { int i = TestTrueFalse(); } bool TestTrueFalse() { int on...

Creating two separate instances from the same class causes them to be linked together?

The problem I am having is I create two different menus from a single class. When I finish the first one, everything is fine. However when I create the second one and set it's region, it modifies the previous one as well. When I call Display() which just flips a boolean variable, it flips it for both instead of just the one I'm calling t...

C++: Is it safe to cast pointer to int and later back to pointer again?

Is it safe to cast pointer to int and later back to pointer again? How about if we know if the pointer is 32 bit long and int is 32 bit long? ...