Difference b/w int* p1 and int *p1

This is a discussion on Difference b/w int* p1 and int *p1 within the C Programming forums, part of the General Programming Boards category; Hello All , is there difference between int* p1 and int *p1 . Code: : int main() { int x ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    11

    Exclamation 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;

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    No. It's just a matter of style.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    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.

  4. #4
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    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.

  5. #5
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    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!!! 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

  6. #6
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Quote Originally Posted by Boomba
    OMG!!! 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;

  7. #7
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Boomba
    OMG!!! 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.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Declare one variable per line, use whatever style you want, and call it a day.
    My best code is written with the delete key.

  9. #9
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Code:
    typedef int *pint;
    pint p, q;
    If you understand what you're doing, you're not learning anything.

  10. #10
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    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.

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by itsme86
    Code:
    typedef int *pint;
    pint p, q;
    That's pure evil.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.


    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    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.

  14. #14
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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?"
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  15. #15
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    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.
    If you understand what you're doing, you're not learning anything.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. messing around with classes: how to use arrays?
    By eastmus in forum C++ Programming
    Replies: 2
    Last Post: 04-21-2009, 08:26 PM
  2. Tic Tac Toe program
    By muzihc in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 08:08 PM
  3. Classes & Collections
    By Max_Payne in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2007, 12:06 PM
  4. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 02:34 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21