DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    5

    Difference b/w int const * and const int *

    please will yu help me to understand the difference b/w int const*p and
    const int *p and why do we use them means what are the significance of these ??
    Last edited by deep725; 02-07-2004 at 02:13 PM.

  2. #2
    Join Date
    Feb 2004
    Location
    Lahore, Pakistan
    Posts
    13
    int const * <--- const pointer

    const int * <-- pointer to const
    Regards,

    Ejaz

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    without boring you with a long lecture on the types of const, there's a simple rule: if the const appears after the *, as in

    int * const p;

    Then the pointer is const, whereas the object to which it points isn't const. If the const appears before the *, either as

    const int * p;

    or

    int const * p;

    Then the object is const, whereas the pointer isn't.

    Const pointers are rather rare, although they have some valid uses. pointers to const objects are much more common and are used in several ways such as passing read only arguments to a function, ensuring that a C-string isn't altered etc.
    Danny Kalev

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links