0% found this document useful (0 votes)
147 views

Pointer (C++) : Prepared By: Irfan Ahmed

Here are some key points to consider in the assignment: - Declare a structure to store account ID (int) and amount (float) - Get number of accounts from user input - Dynamically allocate array of structures of given size - Define function to get input from user and store in structure array - Define function to display records from structure array - Pass pointer to structure array as argument to functions - Use loop to get/display records for each index of array Let me know if any part of the assignment needs more clarification! Pointers, structures, dynamic memory and functions working together can be tricky.

Uploaded by

Sarah Fatima
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Pointer (C++) : Prepared By: Irfan Ahmed

Here are some key points to consider in the assignment: - Declare a structure to store account ID (int) and amount (float) - Get number of accounts from user input - Dynamically allocate array of structures of given size - Define function to get input from user and store in structure array - Define function to display records from structure array - Pass pointer to structure array as argument to functions - Use loop to get/display records for each index of array Let me know if any part of the assignment needs more clarification! Pointers, structures, dynamic memory and functions working together can be tricky.

Uploaded by

Sarah Fatima
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Pointer ( C++)

Prepared by: Irfan Ahmed

Only one thing can remain constant and that is nothing. ( iffi )
Pointer
Variable that stores the memory address
Reference operator (&) is used to access the memory
address of a variable and stores it into the pointer.
Syntax:
o Data type * variable ;
o Such as
• int * a ;

Here, “a” is a pointer variable that can


store the address of another variable.
Enter Value = 7
Example: The value of n is = 7
Void main( ) memory address of n is = 0 x 8f
{ 72ff
int n;
int * a ;
a=&n; cout<<“ Enter value = “ ;
Pointer “a” cin>> n;
storing the
memory a = &n; // Reference operator ( & ) is the address of
address of variable n
“n” cout<<“ the value of n is ” << n;
cout<<“ memory address of n is ” << a;
getch( );

}
Dereference Operator ( * )
It is used to access the value of the variable whose
memory address is stored in the pointer.
“*” is also called indirection operator
example
Output of the program using Dereference
Operator
Use of Pointer in Structure and
Function
Dot operator is not used to access the members of
structure when we use pointer to refer a structure
variable.
In this case, we use selection operator “ -- > ” to
access the structure members.

Let’s we understand this concept with the help of an


example
Output of program
Passing Structure to Function
using Pointers
We can pass the data to function that is stored in a
structure by using Pointers
The way is simple, as we pass the simple variables to
function.
This concept has been elaborated on next slide with the
help of an example.
Output of program
Assignment:
Write a program that Declares structure to store
account ID and amount. It inputs the number of
account holder from the user and creates a dynamic
array of structures to store the records of accounts. The
Program should declare two functions.
First for getting input from the user and Second for
showing records to the user.

( use the concept of Loop, Array, Function and


Pointer )

You might also like