# Difference b/w int* p1 and int *p1

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 08-18-2005
pprabhakar
Difference b/w int* p1 and int *p1
Hello All ,
is there difference between int* p1 and int *p1 .

Code:

``` :           int main() {         int x =3;         int* p1;         int *p2;         p1 = &x;         p2 = &x;         printf("%d\n",*p1);                 printf("%d\n",*p2);         return 0; }```
Code doesn't have any problem.
--------------------------------------------------------

whether really it makes any difference with below ?
int *p1;
int* p1;
• 08-18-2005
anonytmouse
No. It's just a matter of style.
• 08-18-2005
Tonto
Edit: I'm too slow! See above FAQ entry.

No. However, I have heard in a book that the generally accepted method is to do:

Code:

`int *ip;`
Because if you were to do

Code:

`int* ip1, ip2, ip3`
Then you would have the unexpected outcome of ip2 and ip3 being plain int's. Not pointers to integers.
• 08-18-2005
skorman00
To stop some people from pestering me about "you should do it this way or that" I've done the unthinkable:
Code:

`int * p;`
That's right, space on BOTH sides! The revolution starts now.
• 08-18-2005
Boomba
Quote:

Originally Posted by skorman00
To stop some people from pestering me about "you should do it this way or that" I've done the unthinkable:
Code:

`int * p;`
That's right, space on BOTH sides! The revolution starts now.

OMG!!! :eek: This is crazy!!...lol

I usually do int* p

int* - just means "integer pointer" to me.

rather than

int *p - "interger type pointer p" which just doesnt make any sense
• 08-18-2005
Brian
Quote:

Originally Posted by Boomba
OMG!!! :eek: This is crazy!!...lol

I usually do int* p

int* - just means "integer pointer" to me.

rather than

int *p - "interger type pointer p" which just doesnt make any sense

yeah but
int* p, q;
would q be an integer pointer? no.
so it's
int *p, q;
• 08-18-2005
cboard_member
Quote:

Originally Posted by Boomba
OMG!!! :eek: This is crazy!!...lol

I usually do int* p

int* - just means "integer pointer" to me.

rather than

int *p - "interger type pointer p" which just doesnt make any sense

I've noticed C programmers tend to opt for the int *p1; style and C++ programmers opt for int* p1. I prefer the latter myself.
• 08-18-2005
Prelude
Declare one variable per line, use whatever style you want, and call it a day. ;)
• 08-18-2005
itsme86
Code:

```typedef int *pint; pint p, q;```
;)
• 08-18-2005
OnionKnight
I would use something like this:
int* var;
int var1, *var2, var3;

Simply put, when there's a single variable the asterisk stays with the type. This is especially useful for function declarations since compilers usually type their errors in the same fashion.
• 08-18-2005
Dave_Sinkula
Quote:

Originally Posted by itsme86
Code:

```typedef int *pint; pint p, q;```
;)

That's pure evil.
• 08-18-2005
quzah
Quote:

Originally Posted by Dave_Sinkula
That's pure evil.

I agree. I'm thinking a ban is in order. :) I've reported his post as a bad post. :D

Quzah.
• 08-19-2005
kermit
I don't know - I think his intentions are clear enough. I mean, he prefixed a 'p' to the new type. Anybody should easily be able to see what he intended there, even if the code is a few thousand lines long. ;)
• 08-19-2005
Zach L.
I can foresee mass confusion now:

Programmer 1: "Put another variable in there."
Programmer 2: "You want an int?"
Programmer 1: "No, I want a pint."
Programmer 2: "A bit early to start drinking, don't you think?"
• 08-19-2005
itsme86
You guys just don't understand the true power of obscuring data types. Its ability to create chaos and mass confusion is immense. Wielding that power makes you god-like. BUHAHAHAHA.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last