Constants, Manipulators and Operator Precedence in C++

 #include<iostream>

#include<iomanip>
using namespace std;

int main()
{
    // int a = 34;
    // cout<<"The value of a is : "<<a<<endl;
    // a = 42;
    // cout<<"The value of a is : "<<a<<endl;
    // cout<<endl;

    //  Constants in C++
    // const int b = 22;   //Since const, We can't change the value of b here
    // cout<<"The value of b is : "<<b<<endl;
    // b = 78;  //You will get an Error because b is constant
    // cout<<"The value of b is : "<<b<<endl;

    // Manipulators in C++
    int a = 3, b = 78, c = 2387;
    cout<<"The value of a without setw is : "<<a<<endl;
    cout<<"The value of b without setw is : "<<b<<endl;
    cout<<"The value of c without setw is : "<<c<<endl;

    cout<<"The value of a is : "<<setw(4)<<a<<endl;
    cout<<"The value of b is : "<<setw(4)<<b<<endl;
    cout<<"The value of c is : "<<setw(4)<<c<<endl;
    cout<<endl;

    //  Operator Precedence
    int x = 3, y = 4;
    // int z = (x*5) + y;
    int z = ((((x*5) + y) - 45) + 87);
    cout<<z<<endl;

    return 0;
}
//  OUTPUT:
//The value of a without setw is : 3
// The value of b without setw is : 78
// The value of c without setw is : 2387
// The value of a is :    3
// The value of b is :   78
// The value of c is : 2387

// 61

Comments

Popular posts from this blog

Control Structures, If Else and Switch Case Statements in C++

Basic Input/Output & More in C++