C++ Assignment Operator

Introduction

The assignment operator = assigns a value to a variable / object:

int main() /*from  w ww . j  a v a  2s  .co  m*/
{ 
    char mychar = 'c';    // define a char variable mychar 
    mychar = 'd';         // assign a new value to mychar 

    int x = 123;          // define an integer variable x 
    x = 456;              // assign a new value to x 
    int y = 789;          // define a new integer variable y 
    y = x;                // assing a value of x to it 
} 



PreviousNext

Related