Object

Write a program to declare an integer and a pointer to integer. Assign the address of the integer to the pointer and use the pointer to set value and print it.

Algorithm

  1. Declare integer variables i and *j.
  2. Set i = 200.
  3. Set j = &i.
  4. Write *j (i.e., display i’s value using pointer).
  5. Exit.

Flowchart

C++ Source Code

// program 102
#include<iostream>
using namespace std;

int main()
{
  int i, *j;
  i = 200;
  j = &i;
  cout << "\nThe value of i = " << *j;
  return 0;
}

C Source Code

/*program 102*/
#include<stdio.h>

int main()
{
  int i, *j;
  i = 200;
  j = &i;
  printf("\nThe value of i = %d", *j);
  return 0;
}

Output

The value of i = 200

Design a site like this with WordPress.com
Get started