Pointers, C/C++ Programming

When declaring a variable of data type pointer, use the * in front of the variable name. These variables hold a memory location (like B45CDF), not an actual value like 30 or A:

int * Years;

char * Grade;

This tells the program that the value contained in the variable will be a memory address that points to the value at that memory address.

To obtain an actual memory address to use with this variable, the & or reference operator is used.

In the following example, a regular variable is declared. Whenever a variable is declared in a program, the operating system sets aside a memory location in the computer to hold whatever value of a given data type is placed in that memory location. So placing the & in front of a regular variable, tells the operating system that the program wants the memory location address and not the value contained in that memory location.

int LoanYears;

int * Years;

The following code assigns the memory location for the LoanYears variable to the pointer variable.

Years = &LoanYears;

Note: If the assignment was "Years = LoanYears;" a compiler error would occur since the LoanYears is of the wrong data type that Years. Years only accepts memory locations, not actual values.

To assign a value or change the value of LoanYears using the pointer instead of the actual variable, the following code is used:

*Years = 30;

equivalent to

LoanYears = 30;

NOTE: Among the symbols expected in the code are -> and the use of ++ with the pointer variable for the pointer to the struct.

Posted Date: 4/1/2013 3:21:42 AM | Location : United States







Related Discussions:- Pointers, Assignment Help, Ask Question on Pointers, Get Answer, Expert's Help, Pointers Discussions

Write discussion on Pointers
Your posts are moderated
Related Questions
The game of hangman may have originated in the Victorian era, and involves trying to guess a word by suggesting letters. The game is played as follows: A word is chosen and the pl

Binary Options EA for DirectFX and SignalPush Project Description: I want a programmer who will build an EA based on my three types of Binary strategy's using two Indicators.

Overall Program Objective: You will design and simulate a basic RISC processor.   You will create and encode an instruction set.  Your final task will be to "compile" a program


what is the first thing I need to know about Programming?

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Solve the Nine Queens problem recursively. The objective is to place nine queens on an empty chessboard so that no queen is “attacking” any other, i.e., no two queens are in the sa

Suppose that three integer variables intA, intB, and intC have already been defined at the beginning of the main function, write a single C++ statement to read three integers from


recsection method source code for searching position