Simple pointer declaration – CSKC
Sign In

Search

Code Learning #CPP#7503    siteicon   siteicon  

Simple pointer declaration

Understanding how pointer variable is a notation for address of an entity in memory.

Learning Objectives

  • Understanding declaration of a pointer type variable.
  • Understanding use of address of (&) operator.
  • Understanding use of * as de-referencing for reading value of a pointer variable.

Source Code

TC++ #7503

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

int a=10;
This is normal way of variable declaration

int *p=&a;
Here we have declared p with an asterisk which denotes that it contains an address of memory place which is meant to store an integer value. We assign address of a (&a) to p the pointer type variable.

cout<<p<<endl;
Since p is pointer variable so it will contain memory address. The address value show here will be different for different run occasion and different systems as it would be allocated only when the new pointer variable is declared.

cout<<*p<<endl;
This will print 10 contain in the pointer variable p. *p denotes the value at pointer variable p. Remember that at the time of declaration * denotes the type of variable and at the time use it denotes the value at given location.

Notes


Suggested Filename(s): ptr.cpp, simp-ptr.cpp



Share

Created: 20-Sep-2019 00:27 | Updated: 20-Sep-2019 00:28|