Introduction to Operators and Variables in C Asst

Introduction to Operators and Variables in C++ Asst. Prof. Miss. Pooja M. Sindhi. Department of Mathematics KCES’s Post Graduate College of Science Technology and Research, Jalgaon

• Simple program of C++ #include<conio. h> #include<iostream. h> void main() { clrscr(); cout<<“n hello world”; getch(); }

• Void: -When used as a function return type, the void keyword specifies that the function does not return a value. • #include <iostream. h> is a header file library that lets us work with input and output objects, such as cout. Header files add functionality to C++ programs. • #include<conio. h> is a header file library that lets us work with clrscr() and getch() statement. clrscr(): - To clear output screen. getch(): -To get output. Note: - Every C++ statement ends with Semicolon(; ).

C++ Comments can be used to explain C++ code, and to make it more readable. It can also be used to prevent execution when testing alternative code. Comments can be singled-lined or multi-lined. Single-line comments start with two forward slashes (//). Any text between // and the end of the line is ignored by the compiler (will not be executed). This example uses a single-line comment before a line of code:

C++ Variables

Definition: -Variables are containers for storing data values. In C++, there are different types of variables (defined with different keywords), for example: • int - stores integers (whole numbers), without decimals, such as 123 or -123 • double - stores floating point numbers, with decimals, such as 19. 99 or -19. 99 • char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes • string - stores text, such as "Hello World". String values are surrounded by double quotes • bool - stores values with two states: true or false Syntax: type_name variable_name=value; Ex : int a=5;

Operators in C++ : -

Definition: - Operators are used to perform operations on variables and values. C++ divides the operators into the following groups • Arithmetic operators • Assignment operators • Comparison operators • Logical operators


C++ Assignment Operators Assignment operators are used to assign values to variables. In the example below, we use the assignment operator (=) to assign the value 10 to a variable called x: A list of all assignment operators:


C++ Comparison Operators Comparison operators are used to compare two values. Tip: The return value is either true (1) or false (0). You will learn more about them and how to use them in a later chapter. A list of all comparision operators:

C++ Logical Operators: - Logical operators are used to determine the logic between variables or values. A list of all logical operators:

Thank You
- Slides: 14