Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

C++ Dereference Operator

By Sripriya R | on October 14, 2007 |
C++ Tutorials

In this C++ tutorial, you will learn how to access the value of variables pointed by the pointer variables using pointer concept discussed in detail.

It is possible to access the value of variables pointed by the pointer variables using pointer. This is performed by using the Dereference operator in C++ which has the notation *.

The general syntax of the Dereference operator is as follows:

*pointer_variable

In this example, pointer variable denotes the variable defined as pointer. The * placed before the pointer_variable denotes the value pointed by the pointer_variable.

For example:

exforsys = 100;

test = exforsys;

x = &exforsys;

y=*x;

In the above example, the assignment takes place as below:

That is

In the above example, the exforsys is a integer variable having the value of 100 stored in memory address location 3501.

The variable exforsys is assigned to the variable test in the second statement:

test = exforsys;

The value of the variable exforsys is 100 and is then copied to the variable test.

In the third statement, the address of the variable exforsys denoted by reference operator &exforsys is assigned to the variable x as:

x = &exforsys;

The address of the variable 3501 and not the contents of the variable exforsys is then copied into the variable x.

The fourth statement makes use of the deference operator:

y=*x

This means that the value pointed to by the pointer variable x gives the value 100 to y.

Some points for the programmer to note:

  • The programmer must note that the x refers to the address 3501 whereas *x refers to the value stored in the address 3501 namely 100. .
  • The reference operator is denoted by & and deference operator denoted by * . Both differ in their meaning and functionality. The reference operator denotes the address of. The dereference operator denotes the value pointed by. In short, a deference variable can be denoted as referenced. .
  • If the programmer wants to define more than two pointer variables, then comma operator may be used in this instance. The programmer must carefully place pointer symbol * before each pointer variable.

For instance, if the user wishes to define two integer pointer variables, e1 and e2, this can be done as follows:

int *e1,*e2;

If the programmer declares:

int *e1,e2;

This means that e1 is a pointer variable pointing to integer data type but e2 is only an integer data type and not a pointer type. The programmer must ensure to place * before each pointer variable.

The dereferencing or indirect addressing is performed using the indirection operator * used to access the value stored in an address.

The defining of pointer variable:

int* exf;

The definition of pointer variable as in the above case is the pointer variable exf.

It is also possible to assign value to pointer variable using indirection operator. This gives the same effect as working with variables.

For Example:

  1.  #include <iostream>
  2. using namespace std; 
  3. void main()
  4. {
  5. 	int example,test;
  6. 	int* exforsys;
  7. 	exforsys=&example;
  8. 	example=200;
  9. 	test=200;
  10. 	*exforsys=100;
  11. 	test=*exforsys;
  12. 	cout << *exforsys << endl << test; 
  13. }

The output of the above program is

In the above example, the pointer variable exforsys points to integer variable example and takes the address of the variable example as:

test and example have initial values of 200.

The statement:

*exforsys=100

Sets the value of the variable pointed by pointer variable exforsys as 100. This is equivalent to setting example=100.

The assignment is as follows:

example test

The statement

test=*exforsys;

sets the value of variable test with the value pointed by the pointer variable exforsys which is 100 as seen in the above example. Test also becomes 100 and the assignment becomes:

Both results are displayed having the value 100.

Defining pointers and using them to access the variable pointed by them is an important concept thoroughly detailed in this tutorial. In the next section, the powerful concept of pointers with other features of C++ such as arrays and functions will be explained in detail.

« « C++ Memory Management Operators
Service Composability » »

Author Description

Avatar

Ads

Free Training

RSSSubscribe 416 Followers
Ads
  • Popular
  • Recent
  • C++ Variables Scope in Functions

    October 17, 2006 - 0 Comment
  • How to Access C++ Class Members

    August 21, 2007 - 0 Comment
  • C++ Void Pointer and Null Pointer

    October 12, 2007 - 0 Comment
  • C++ Structure

    August 19, 2007 - 0 Comment
  • C++ Inheritance

    August 19, 2007 - 0 Comment
  • C++ Standard Input Output Stream

    August 24, 2007 - 0 Comment
  • C++ Memory Management Operators

    October 12, 2007 - 0 Comment
  • C++ String Representation and Handling

    September 8, 2007 - 0 Comment
  • C++ Static Functions

    February 12, 2007 - 0 Comment
  • C++ Operators Part I

    August 24, 2007 - 0 Comment
  • C++ Memory Management Operators

    October 12, 2007 - 0 Comment
  • C++ Void Pointer and Null Pointer

    October 12, 2007 - 0 Comment
  • C++ Pointers

    October 1, 2007 - 0 Comment
  • C++ Static Functions

    October 1, 2007 - 0 Comment
  • C++ Friend Functions

    September 28, 2007 - 0 Comment
  • C++ Pure Virtual Function and Base Class

    September 28, 2007 - 0 Comment
  • C++ Virtual Functions

    September 25, 2007 - 0 Comment
  • C++ Inline Functions

    September 25, 2007 - 0 Comment
  • C++ Function Passing Types

    September 12, 2007 - 0 Comment
  • C++ Storage Classes

    September 10, 2007 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • C++ Memory Management Operators
  • C++ Void Pointer and Null Pointer
  • C++ Pointers
  • C++ Static Functions
  • C++ Friend Functions

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2021. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.Accept Reject Read More
Privacy & Cookies Policy
Necessary Always Enabled