Pointers, C/C++ Programming

Assignment Help:

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.


Related Discussions:- Pointers

Implement a binomial tree class, a) Implement a binomial tree class with a ...

a) Implement a binomial tree class with a method that calculates the value of an option passed in to the class. The binomial tree should not rely on specific features of the differ

Stone Game - Remove Last, #include int main() { int T; ...

#include int main() { int T; int N; int i; scanf("%d",&T)

Need solution for simple beginner level c program, search words from a pass...

search words from a passage and return snippets in html format..

ASCII, A string S is said to be "Super ASCII", if it contains the character...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

AlgorithmS, Algorithm to find the value of the powers raised by integer

Algorithm to find the value of the powers raised by integer

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd