Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: C and Cpp Programming in C and Cpp Pointers and References in C++ Tutorial

The ability to manipulate memory and memory locations directly is part of what makes C and C++ so powerful, so dangerous, and so difficult for beginners. C only has pointers, but C++ uses pointers and references that have a nicer syntax and attempt to be

Tutorial Details:

Pointers and References in C++

The ability to manipulate memory and memory locations directly is part of what makes C and C++ so powerful, so dangerous, and so difficult for beginners. C only has "pointers", but C++ uses pointers and "references" that have a nicer syntax and attempt to be safer. This article will attempt to demystify these concepts in the minds of beginning C/C++ programmers.

This article assumes the reader has a basic understanding of C/C++ including variable declaration, conditionals, loops, functions, and data types. This article will speak more specifically about C++.

Remember, pointers can twist your mind at first and they are a difficult concept to grasp. Often times it is hard to see where they would be useful.

The Basics
The "normal" way of storing information (data) in C++ is using certain predefined types like integers (int), floating point values (float, double), and characters (char). The programmer tells the compiler about the data he wishes to store by giving its type, its name, and possibly an initial value.

None of this should be new or difficult. This is easy, assuming you know the different types, and the best part about it is that the compiler takes care of finding a place to store the variable and we just tell it when we want to know what is "stored" in the variable. But wait! The compiler knows where the variable is stored in memory, it has to. We can get at the address of a variable by using the address of operator, "&" (ampersand).

But why would we care about knowing the address of our variables? The compiler takes care of storing our data for us, right? Yes, and we as humans have very little use of printing out the addresses of variables except for debugging purposes. But we can store an address of a variable into a special data type called a pointer and the compiler takes care of storing our "pointer value" for us. We designate pointers with a data type (int, float...) followed by the * (asterisk) symbol.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
C and Cpp Programming in C and Cpp Pointers and References in C++ Tutorial

View Tutorial:
C and Cpp Programming in C and Cpp Pointers and References in C++ Tutorial

Related Tutorials:

Accelerate your Java apps! - JavaWorld - September 1998
Accelerate your Java apps! - JavaWorld - September 1998
 
Java Tip 68: Learn how to implement the Command pattern in Java - JavaWorld - February 1999
Java Tip 68: Learn how to implement the Command pattern in Java - JavaWorld - February 1999
 
Java memory management
Java memory management
 
Smart object-management saves the day - JavaWorld November 1999
Smart object-management saves the day - JavaWorld November 1999
 
C# : A language alternative or just J--? (part1)
C# : A language alternative or just J--? (part1)
 
C#: A language alternative or just J--?, Part 2 - JavaWorld December 2000
C#: A language alternative or just J--?, Part 2 - JavaWorld December 2000
 
Pick up performance with generational garbage collection
Pick up performance with generational garbage collection
 
Integrate Java and C++ with Jace
Integrate Java and C++ with Jace
 
Java is here to stay (JavaWorld / January 2000 / by John Rommel)
Java is here to stay (JavaWorld / January 2000 / by John Rommel)
 
Java's character and assorted string classes support text-processing
Java's character and assorted string classes support text-processing
 
The J2EE 1.4 Tutorial
The J2EE 1.4 Tutorial is a guide to developing enterprise applications for the Java 2 Platform, Enterprise Edition (J2EE) version 1.4. Here we cover all the things you need to know to make the best use of this tutorial.
 
Does an object exist if you can't test its identity?
Does an object exist if you can't test its identity?
 
Sizeof for Java
Sizeof for Java
 
JTwain
JTwain will implement a Java interface to the the Win32 C DLL TWAIN acquire methods.
 
Java Technology Fundamentals
Learn how to use variable arguments lists, the new JConsole utility to monitor applications, and discover ways to learn what you need to know to get Sun certified.
 
10 Minutes Guide to Ant
10 Minutes Guide to Ant 10 Minutes Guide to Ant Previous Tutorial Index Next Introduction Well for the next 10 minutes get ready to devote to the ant guide. This will make some sence to the ant. Ant is a free tool under GNU Licence and is
 
Building Web Application With Ant and Deploying on Jboss 3.0
Building Web Application With Ant and Deploying on Jboss 3.0 Building Web Application With Ant and Deploying on Jboss 3.0 Previous Tutorial Index Next In this lesson I will show you how to build you web application and install on the Jboss 3.0
 
Parisonz Solutions!
Parisonz Solutions! W elcome to Parisonz Solutions . The purpose of this web is to Develop and Distribute Projects to Businesses and Individuals though Web. We have a wide range of projects completed online — including software development, web
 
New Technical Articles: 64-bit Programming on Solaris 10 OS for x86 Platforms
Four technical articles describe the new Sun Studio 10 software's 64-bit programming features on the Solaris 10 OS for x86 and AMD64 platforms. Important issues regarding the AMD64 ABI (Application Binary Interface), debugging, migration to 64-bits, and p
 
Using DTrace to Profile and Debug A C++ Program (Technical Article)
In this test case, the DTrace capability in the Solaris 10 OS is used to identify an error common to C++ applications -- the memory leak.
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.