Illustrates the use of a public variable : Public « Class « C++






Illustrates the use of a public variable

Illustrates the use of a public variable
  

#include <iostream>

using namespace std;

class myclass {

public:
  int i, j, k; // accessible to entire program
};

int main()
{
  myclass a, b;
  a.i = 100; 
  a.j = 4;
  a.k = a.i * a.j;
  b.k = 12; 
  cout << a.k << " " << b.k;
  return 0;
}

           
         
    
  








Related examples in the same category

1.Assign the public object member address to a pointerAssign the public object member address to a pointer
2.public class extending
3.field in struct is public by default
4.Class with only public fields and methods
5.Virtual public inheritance
6.public data field
7.public inheritance from three parent classes