0% found this document useful (0 votes)
21 views

Lecture 6

Uploaded by

Koushal Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
21 views

Lecture 6

Uploaded by

Koushal Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
CodeWithHarry Menuv f Q Show Course Contents @ Overview Q&A Downloads Announcements C++ Header files & Operators | C++ Tutorials for Beginners #6 In this C++ tutorial, we will talk about header files and operators. In our last lesson, we discussed the basic input and output. Lets now cover header files and operators in C++ language: Header Files in C++ “#include" is used in C++ to import header files in our C++ program. The reason to introduce the "" header file into our program is that functions like "cout" and “cin" are defined in that header file. There are two types of header files: System Header Files System header files ships with the compiler. For example, “#include ”. To see the references for header files click here User-Defined Header Files The programmer writes User-defined header files himself. To include your header file in the program, you first need to make a header file in the current directory, and then you can add it. Operators in C++ Operators are used for producing output by performing various types of calculations ‘on two or more inputs. In this lecture, we will see the operators in C++. Arithmetic Operators Arithmetic operators are used for performing mathematical operations like (+, -, *). The arithmetic operators are shown in Figure 1 coutc< tices eoniees Eotioes Eotice eoieas cout<< cout<< regs Eories oes sey Figure t Arithmetic Operators 1. The function "a+b", will add a and b values and print them. 2. The function "a+b “will subtract a and b values and print them. 3. The function “a*b" will multiply a and b values and print them. 4. The function "a/b", will divide a and b values and print them. 5. The function "a%b " will take the modulus of a and b values and print them. 6. The function “a++" will first print the value of a and then increment it by 1. 7. The function "a- ", will first print the value of a and then decrement it by 1. 8. The function "44a", will first increment it by one and then print its value. will first decrement it by one and then print its value. The output of these arithmetic operators is shown in figure 2. Figure 2: Arithmetic Operators Output » Assignment Operators Assignment operators are used for assigning values to variables. For example: int a = 10,b=5; * Comparison Operators Comparison operators are used for comparing two values. Examples of comparison operators are shown in figure 3. corre Corioes eories oles 5 eer ecm : (Creer ones : Cro ees onccamtr f pECCCLC ORC Figure.2: Comparison Operators 1. The function "(a==b)’, will compare a and b values and check if they are equal. The output will be one if equal, and 0 if not. 2. The function" ', will compare a and b values and check if" "is not equal to" The output will be one if not equal and 0 if equal. 3. The function "(a>=b)", will compare a and b values and check if “a” is greater than or equal to "b". The output will be one if greater or equal, and 0 if not. 4. The function "(aé: ill compare a and b values and check if "b" is greater than or equal to "a". The output will be one if greater or equal, and 0 if not. ‘a" is greater than "b". 5. The function "(a>b)',, will compare a and b values and check if The output will be one if greater and 0 if not. 6. The function "(a¢b)’,, will compare a and b values and check if "b" is greater than "a’. The output will be one if greater and 0 if not. The output of these comparison operators is shown in figure 4. Logical Operators Logical operators are used for comparing two expressions. For example ((a==b) && (a>b)). More examples of logical operators are shown in figure 5. Ceissa seein logical op eee Con Ceca eve ate ) 8B (ach) Is:" // 2, User defined header files: It is written by the programmer // #include "this.h" //--> This will produce an error if this.h is no using namespace std; int main(){ int a=4, be5; cout<<"Operators in C++:"< used to assign values to variables // int a =3, b=9; // char d="d"; // Comparison operators cout<<"Following are the comparison operators in C++"<= b is “<<(a>=b)< b is "<<(a>b)<

You might also like