![]() |
| | #1 |
| Registered User Join Date: Dec 2008
Posts: 13
| I am puzzled by a question lately, to wich I can't find an answer. What is the difference between the next pointer initialization methods: Code: int* pointer_name=NULL Code: int *pointer_name=NULL As I was searching the web for answers, I found another interesting example, where the pointer was initialized like this: Code: int * pointer_name=NULL Big thanks in advance for everyone, reading this. |
| laczfinador is offline | |
| | #3 |
| ... Join Date: Jan 2003
Posts: 1,190
| Just keep in mind that doing Code: int* p1, p2; Code: int* p1, *p2; Code: int* p1, * p2; |
| kermit is offline | |
| | #4 |
| Registered User Join Date: Dec 2008
Posts: 13
| Hm... I am trying to understand how does the next function works. It is from a SDL game programming tutorial. Code: SDL_Surface *load_image(char filename[])
{
SDL_Surface* loadedImage=NULL;
SDL_Surface* optimizedImage=NULL;
loadedImage=SDL_LoadBMP(filename);
if(loadedImage!=NULL)
{
optimizedImage=SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}
Thanks for the answers so far! |
| laczfinador is offline | |
| | #5 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| http://www.research.att.com/~bs/bs_faq2.html#whitespace Bjarne "explains" the difference between the two styles. I prefer the first one, and find the 3rd one acceptable, as well.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #6 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| I like the 2nd one because it makes the most sense, and you can consider it the same as dereferencing
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #7 |
| Registered User Join Date: Dec 2008
Posts: 13
| Now, that is the kind of answer I was looking for! Thanks a lot everyone, for helping me out! |
| laczfinador is offline | |
| | #8 | ||
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Quote:
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| ||
| Elysia is offline | |
| | #9 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #10 | |
| ... Join Date: Jan 2003
Posts: 1,190
| Quote:
Code: double *p, q; I think Stroustrup makes a good point about declaring each pointer one per line. Again, whichever style one chooses, it is good to be consistent. * - I would add that I am undoubtedly biased by the fact that C is the first language I learned and though I dabble in other languages (most recently I have taken up the task of becoming competent in C++ programming) it is still my 'primary' language. I have also gotten used to K&R style. Had I learned C++ first, I guess I would probably be more inclined to the 'Stroustrup style' of declaring a pointer with the asterisk next to the type rather than the name... Last edited by kermit; 01-18-2009 at 12:31 PM. | |
| kermit is offline | |
![]() |
| Tags |
| asterisk, initialization, pointer, position |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Ban pointers or references on classes? | Elysia | C++ Programming | 89 | 10-30-2007 03:20 AM |
| sorting with pointer of pointers to array | dunpealslyr | C++ Programming | 6 | 10-01-2007 11:26 PM |
| pointers | InvariantLoop | C Programming | 13 | 02-04-2005 09:32 AM |
| God | datainjector | A Brief History of Cprogramming.com | 746 | 12-22-2002 12:01 PM |
| Contest Results - May 27, 2002 | ygfperson | A Brief History of Cprogramming.com | 18 | 06-18-2002 01:27 PM |