Chapter 1c++
Chapter 1c++
return 0;
}
Cont.…
4. Blocks are the group of statements that are enclosed within { } braces.
They define the scope of the identifiers and are generally used to enclose the
body of functions and control statements.
Syntax: {
return 0;}
• Example
#include <iostream> a = a + 1;
int a, b; return 0;
a = 9;
Identifiers
• It is a name given to any program element, the elements might be
variable, function, array, structure or class.
// of various data types on your computer. cout << sizeof(long) << endl;
#include <iostream> cout << sizeof(float) << endl;
using namespace std; cout << sizeof(double) << endl;
int main() return 0;
{ }
cout << sizeof(char) << endl;
Constant C++
In C++ symbolic constant is declared two ways .These are using the const
keyword and #define
Literal constant
#include<iostream>
using namespace std;
int main(){
float x=3.5;
float y=7.8, sum;
x=9.5;
sum=x+y;
cout<<"The sum of x and y is\t"<<sum<<endl;
return 0;
}
Define constant
#include<iostream>
#define x 9.5
int main(){
sum=x+y;
return 0;
}
Const constant
#include<iostream>
using namespace std;
int main(){
const float x=10;
float y=9,sum;
x=20;
sum=x+y;
cout<<"The sum of x and y is\
t"<<sum<<endl;
return 0;
}
Assignment Operator (=)
Causes the operand on the left side of the assignment statement to
have its value changed to the value on the right side of the statement
variable
Syntax: operand1=operand2;
These operators are used for the comparison of the values of two
operands. For example, ‘>’ checks if one operand is greater than the
other operand or not, etc.
The result returns a Boolean value, i.e., true or false.
Cont..
Cont..
#include <iostream> cout << (x < y) << endl;
using namespace std; // Equal to operator
cout << (x == y) << endl;
int main() // Greater than or Equal to operator
{ cout << (x >>= y) << endl;
int x = 8, y = 2;
// Greater than operator // Lesser than or Equal to operator
cout<< (x > y) << endl; cout << (x <= y) << endl;
// not return 0;
cout << (x != y) << endl; }