Thread: Pointers...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    Qatar
    Posts
    39

    Pointers...

    Hi, i am a new one in programming, please help me in finding out the difference among the two statements.


    First syntax
    Code:
    volatile unsigned int *mec=(volatile unsigned int *)0x01f80000;

    Second Syntax
    Code:
    volatile unsigned int *mec;
    mec=(volatile unsigned int *)0x01f80000;

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Look up the difference between initialisation (or initialization for those challenged with the english language) and assignment.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Location
    Qatar
    Posts
    39
    @grumpy if u can further explain it, it will be helpful

  4. #4
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    Code:
    volatile unsigned int *mec;
    mec=(volatile unsigned int *)0x01f80000;
    Here, 1st statement is declaration of mec and 2nd one is definition of mec !

    Code:
    volatile unsigned int *mec=(volatile unsigned int *)0x01f80000;
    Here the declaration and the definition have been clubbed together !

  5. #5
    Registered User
    Join Date
    Sep 2010
    Location
    China
    Posts
    12
    If mec is an auto local variable(no static precedes volatile unsigned int), they are identical.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by rehan View Post
    @grumpy if u can further explain it, it will be helpful
    I'd argue you will benefit more by working out the answer for yourself. I've given you a hint to get you started on that.

    AnishaKaul, you're barking up the wrong tree.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by AnishaKaul View Post
    Code:
    volatile unsigned int *mec;
    mec=(volatile unsigned int *)0x01f80000;
    Here, 1st statement is declaration of mec and 2nd one is definition of mec !

    Code:
    volatile unsigned int *mec=(volatile unsigned int *)0x01f80000;
    Here the declaration and the definition have been clubbed together !
    Incorrect.

    volatile unsigned int* mec;

    Is both a declaration and a definition.
    It does not need an assignment to be a definition. And assignment certainly isn't a definition.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    I apologize for the mis-information in the post number 4 !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays with pointers
    By Niels_M in forum C Programming
    Replies: 18
    Last Post: 07-31-2010, 03:31 AM
  2. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 05:19 AM
  3. Replies: 7
    Last Post: 05-19-2010, 02:12 AM
  4. pointers to arrays
    By rakeshkool27 in forum C Programming
    Replies: 1
    Last Post: 01-24-2010, 07:28 AM
  5. Pointers pointers pointers....
    By G'n'R in forum C Programming
    Replies: 11
    Last Post: 11-02-2001, 02:02 AM