-
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.
-
int const * <--- const pointer
const int * <-- pointer to const
Regards,
Ejaz
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks