Hii. I'm semi- new to programming and I thought I was pretty comfortable with pointers, but I've come across a few examples in books (openGL red book, and some sdl book.) where pointers have been used in unfamiliar context.
For example:
const char *windowName= "PONG"
I saw this in a tutorial and was unsure why the pointer was necessary, and how is thechar more than one character long without it being a character array or string... I'm guessing that initializing windowName as a pointer has something to do with this?
Also from an sdl tutorial:
SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
SDL_HWSURFACE | SDL_DOUBLEBUF );
What is happening here when the object: 'screen' has been initialized as a pointer? I know how pointers are used to make the the variable set as pointer, point to the value of another variable and stuff; but I don't see how it would work for a class, or a functions with arguments and stuff.
Sorry, this is probably a stupid question; but I'm struggling to get my head around pointers.
This is traditionally referred to as a "C-style string", as it is the dominant way to handle strings in the C programming language (and it's the wrong way to do it in C++). The pointer points to the first character of the string, and the string ends with a null character. It is called a null-terminated character sequence. C++ strings are not null terminated, and as such can contain the null character without problem.
As for your second question, I'm not sure why you're confused - have you never dynamically allocated a class type before?
Thanks for your help on the first question.
I have a very brief knowledge of how pointers work, to be honest.
I know how they work for simple integers for example:
int* a;
int b = 5;
int c;
a = &b;
c = *a;
c would equal 5.
I don't see how a pointer could equal the value pointed by SDL_SetVideoMode... would it equal the return value of the function?