GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 6 of 437    Print  
What is a const pointer?

  
Total Answers and Comments: 4 Last Update: June 09, 2007   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Prasad
 
Constant pointer is NOT pointer to constant. Constant pointer means the pointer is constant. For eg:
Constant Pointer
int * const ptr2 indicates that  ptr2 is a pointer which is constant. This means that ptr2 cannot be made to point to another integer. However the integer pointed by ptr2 can be changed.



Where as a Pointer to constant is
const int * ptr1 indicates that ptr1 is a pointer that points to a constant integer. The integer is constant and cannot be changed. However, the pointer ptr1 can be made to point to some other integer.

Above answer was rated as good by the following members:
selloorhari, bhavyam, tigersasi
October 04, 2005 12:07:46   #1  
mayank        

RE: What is a const pointer?
There are cases when you need to define a constant pointer to a variable/object; for instance, when taking a function address, or when you want to protect a pointer from unintended modifications such as assignment of new address, pointer arithmetic, etc.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
April 27, 2007 04:30:24   #2  
Prasad        

RE: What is a const pointer?
Constant pointer is NOT pointer to constant. Constant pointer means the pointer is constant. For eg:
Constant Pointer
int * const ptr2 indicates that  ptr2 is a pointer which is constant. This means that ptr2 cannot be made to point to another integer. However the integer pointed by ptr2 can be changed.



Where as a Pointer to constant is
const int * ptr1 indicates that ptr1 is a pointer that points to a constant integer. The integer is constant and cannot be changed. However, the pointer ptr1 can be made to point to some other integer.

 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 0Overall Rating: +3    
June 08, 2007 19:34:48   #3  
neverd Member Since: June 2007   Contribution: 11    

RE: What is a const pointer?
A pointer that cannot be changed to point other memory or object, however the value it points to can be changed.
 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
June 09, 2007 05:04:39   #4  
pradeep kumar v.v.n.k        

RE: What is a const pointer?
a const pointer means the pointer which represents the address of one value. so if you declare a pointer inside the function, it doesn't have scope outside the function. if it is also available to the outside function whenever we declare a pointer as const.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape