Tuesday, October 23, 2018

Pointers and Array


Pointer and Arrays


Pointer Definition


Pointer is a variable that store the address of another variable
Syntax :
<type> *ptr_name;
Two operators mostly used in pointer : * (content of) and & (address of)
Example: 
Initialize an integer pointer into a data variable: 
int i, *ptr;
ptr = &i;
To assign a new value to the variable pointed by the pointer:

*ptr = 5;  /* means i=5 */ 

   Pointer Concept

   Pointer To Pointer

•Pointer to pointer is a variable that saves another address of a pointer or is a form of multiple indirection, or a chain of pointers. Normally, a pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value as shown below.
Syntax:
  <type> **ptr_ptr ;
Example:
  int i, *ptr, **ptr_ptr;
  ptr = &i;
  ptr_ptr = &ptr;
  To assign new value to i:
  *ptr = 5;  // means i=5 ;
  **ptr_ptr = 9;   // means i=9; or *ptr=9;



2201766173

binus.ac.id
skyconnectiva.com
Aviel Leonardo Wijaya

No comments:

Post a Comment