× About Us How it works Pricing Student Archive Subjects Blog Contact Us

What are different types of operators in Programming?

Operators are the set of symbols that are used in a programming language to perform mathematical and logical operations.  

There are mainly five types of operators present in any language. Here we’ll be discussing operators specific to C/C++ language. 

Let’s dive deep and understand each category separately.  

1). Arithmetic Operators  

These operators are used to perform mathematical operations such as addition, multiplication, division, increment/decrement, subtraction and modulus.  

The values on which operators works are called operands.  

In the following article, let’s take two operands namely x & y.  

Arithmetic Operators 
Operation  Symbol  Usage  Explanation  
Addition  +  x + y  Adds x and y, irrespective of their placement  
Subtraction    x – y  Subtracts the right operand (y) from the left (x) 
Multiplication  *  x * y  Multiplies a and y, irrespective of their placement 
Division  /  x / y  Divides left operator (x) by right operator (y) and returns the quotient. 
Increment  ++  x++  The operand is incremented by 1.  
Decrement    x–  The operand gets decremented by 1. 
Modulus   %  x % y  Divides left operator by right operator and returns remainder.  

2). Relational Operators  

These operators are used to draw comparison between two operands.  

They check values such as greater than, less than, equal to, etc and return the answer as TRUE (1) or FALSE (0).  

You need to be very careful in selecting “=” or “==” as both of them convey different meaning.  

“=” comes under the category of assignment operators and “==” is used when we are comparing two values whether they are equal or not.  

Relational Operators 
Operation  Symbol  Usage  Explanation  
Equal to  ==  x == y  Returns TRUE if first operand (x) is equal to second operand (y). 
Not equal to  !=  x != y  Returns TRUE when first operand (x) is not equal to second operand (y). 
Greater than  >  x > y  Return TRUE when first operand (x) is greater than second operand (y). 
Less than   <  x < y  Return TRUE when x is less than y. 
Greater than equal to  >=  x >= y  Return TRUE when x is greater than or equal to y. 
Less than equal to  <=  x <= y  Return TRUE when x is less than or equal to y. 

 

3). Logical Operators  

This operator deals with logical operations performed on the Boolean values of the operators. It includes Logical AND, OR and NOT operators.  

In C/C++, a non-zero number is considered as BOOLEAN TRUE or 1. If it’s a character or a special character, the corresponding ASCII Values are taken. 

This may hold true for certain other languages.  

Logical Operators 
Operation  Symbol  Usage  Explanation  
Logical OR  ||  x || y  Returns TRUE (1) if any of the operand is TRUE, else returns FALSE or 0. 
Logical AND  &&  x && y  Returns TRUE (1) when both the operands are TRUE else returns FALSE (0).  
Logical NOT  !   !x  This is a unary operator and returns TRUE (1) if the operand is FALSE (0) and vice versa.  

 

4). Assignment Operators  

This operator deals with logical operations dealing with Boolean values of the operators. It includes Logical AND, OR and NOT operators.  

In C/C++, a non zero number is considered as BOOLEAN TRUE or 1. If it’s a character or a special character, the corresponding ASCII Values are taken. 

This may hold true for certain other languages.  

Assignment Operators 
Operation  Symbol  Usage  Explanation  
Value assigning   =  x = y  Here the value of right operator (y) is assigned to left operator (x). 
Add and assign  +=  x += y  x= x + y; Here both the operands are added and the value is assigned back to first operand. 
Subtract and assign   -=  x -= y  x= x – y; The second operand is subtracted from first and the result is assigned to first operand. 
Multiply and assign  *=  x *= y  x = x * y; Both the operands are multiplied and the result is then assigned to the first operand.  
Divide and assign   /=  x /= y  x = x / y; First operand is divided by second and the quotient is assigned to the first operand.  
Modulus and assign  %=  x %= y  x = x % y; First operand is divided by second and the remainder is assigned to the first operand. 

 

5). Bitwise Operators  

These are special types of operators which convert the decimal representation of the number to binary ad then perform the operation bit by bit.  

The final result is again converted back into decimal number.  

The main advantage of these functions is that they boost the processing speed as well efficiency of the program.  

Bitwise Operators 
Operation  Symbol  Usage  Explanation  
Bitwise OR  &  x | y  Both the operands x and y are converted into binary. The OR operation is performed bit by bit. The final answer is again converted back into decimal number.   
Bitwise AND  |  x & y  Both the operands x and y are converted into binary. The AND operation is performed bit by bit. The final answer is again converted back into decimal number.   
Bitwise Exclusive OR  ^  x ^ y  Exclusive OR operation is performed but by bit after converting the operands into binary system. 
Complement   ~  ~x  It’s a unary operator. All the bits are complemented to deliver the final answer.  
Left Shift  <<  x << y  Here the left bits of the operand (x) are moved as specified by the second operand (y). It is more like multiplying x with 2y. 
Right Shift  >>  x >> y  Here the right bits of the operand are moved specified by the operand y. It’s like dividing x by 2y. 

Elevation Designer

Reference – If you want rendering services then click here.

Read More – Coding and Programing Questions

View More – Useful links for Your Child’s Development 

What are the major types of functions in program?

A Function contains a set block of statements that are written outside of the main program and are executed to perform a desired set of operations.  

This function may or may not take data from the primary function.  

Using functions the modularity of the program is boosted as a large program gets divided into smaller sections. This makes the code optimized, reusable and scalable too.  

Functions are known by different names in different programming languages such as methods, subroutines, procedures etc.  

There are primarily two types of Functions: 

1). In-built or Pre-defined Functions or Library functions  

All the programming languages contain some built-in functions such as standard input/output functions, maths functions etc. These functions are listed in files called as system libraries. 

To use a function, you need to add that library in your code. This helps in writing the code error free.  

The system library is usually included in the code before the main() function begins. 

For example: sqrt(); function is used to find the square root of any number and is defined in the library  math.h header file in C programming language. 

This function can easily be called as: 

x = sqrt (y); (y should be positive) 

Here, square root of y is calculated and the returned value is stored in the variable x. 

2). User-defined functions  

These functions are defined and created by the programmer or the person doing the coding.  

Functions are properly created and tested as per a working and optimal algorithm before going for the final builds.  

You don’t have to include any header file and the functions are defined in the same file containing the main() function.  

Now depending on the arguments passed and return values the functions fall in four different categories: 

1. Without Parameters and without return values 

As, there is no return value, the return type of the function becomes “void”. 

For example: Let’s code a program in C to add two numbers without passing any arguments. 

#include <stdio.h>
#include <conio.h>
void main()
  {
    void sum();    //declaring the function
    sum();          // calling the function
    getch();
  }
void sum(){
  int a,b,c;
  printf(“Enter two numbers: \n”);
  scanf (“%d%d”, &a, &b);
  c= a+b;
  printf(“Sum = %d”, c); // printing the answer
}
Output Screen:
Enter two numbers:
12 45
Sum = 57

Let’s understand the flow of control: 

  1. sum() is defined with return type void  as nothing is intended to be returned. 
  2. The function sum() is called from the main function. 
  3. Control pauses the main() function and shifts to the first line of the function. 
  4. The addition is performed and the result is printed.  
  5. Control jumps back to the main() function without taking anything back. 

2. Without parameters but with return values 

User creates a function that returns a value but no parameters are passed. 

Understand the same addition program defined using without using parameters that returns an integer value.  

#include <stdio.h>
#include <conio.h>
void main()
  {
    int sum();    //declaring the function
    int c;
    c = sum();    // function is called and value is returned
    printf(“Sum = %d”,c);
  }
int sum(){
  int a,b,c;
  printf(“Enter two numbers: \n”);
  scanf (“%d%d”, &a, &b);
  c= a+b;
  return c; // the addition of two number is returned
}
Output Screen:
Enter two numbers:
34 56
Sum = 90

Flow of control: 

  1. sum() is declared with a return type int. This means that the function will be returning an integer value. 
  2. The function sum() is called from the main function with no parameters. 
  3. The assignment operator “ = “ is ensuring that the returned value is captured and assigned to a variable.   
  4. Control pauses the main() function and shifts to the first line of the function. 
  5. The addition is performed and the result is sent back to the main function.  
  6. The value is captured in a variable and printed on the console.  

3. With parameters and without return values 

Here parameters are sent in the function but nothing is returned. This makes the return type “void”. 

One thing is to remember here is to ensure that the datatypes of the variables that are passed should be same as that defined in the function. Else the compiler will give an error.  

Check the same addition function made using the parameter values but does not returns anything. 

#include <stdio.h>
#include <conio.h>
void main()
{
  void sum (int, int);    //declaring the function
  int a,b;
  printf(“Enter two numbers”);
  scanf(“%d%d”, &a, &b);
  sum(a,b);
  getch();
}
void sum(int a, int b){
  int c;
  c= a+b;
  printf(“Sum = %d”,c); // nothing is returned
}
Output Screen:
Enter two numbers:
34 89
Sum = 123

Things to consider: 

Since the function sum() is uses two parameters that are integers. The function definition should also contain only two parameters that are integer. 

Any mismatch will give error. The function will not work. 

Always remember:   

void sum (int, int);  and void sum (int, int, int); and int void (int,int);  are all different. You need to be very careful about what exactly you want your function to do. 

4. With both parameters and return values  

Now, let’s see how to make a function that performs addition using return type as well as with parameters.  

#include <stdio.h>
#include <conio.h>
void main()
{
  int sum (int, int);    //declaring of function
  int a,b,c;
  printf(“Enter two numbers”);
  scanf(“%d%d”, &a, &b);
  c = sum(a,b);       // calling the function
  printf(“Sum=%d”,c);
  getch();
}
int sum(int a, int b){
  int c;
  c = a+b;
  return c;     // value returned
}
Output Screen:
Enter two numbers:
45 67
Sum = 112

Flow of control:  

  1. Here copies of the parameters are passed to the called function from the calling function. 
  2. The copies are received as parameters in the called function. 
  3. Body is executed and the sum is returned to the called function where it is displayed using a printf() function.    

 

Read More – Coding and Programing Questions

View More – Useful links for Your Child’s Development 

What are Functions in program?

Functions are the block of statements encapsulated together and are designed to achieve a specific outcome.  

The values that are passed are called the parameters or arguments and the function may or may not return a value.  

Different programming languages have different names for functions such as procedures, methods etc. 

Why do we use functions? 

  • Make the code clean, clear and well defined. 
  • The code is easy to debug and scale. 
  • Boosts modularity 
  • Makes the code reusable 
  • Significantly lowers down the LOC which is a great sign of good programming. 
  • Optimized code  

What happens when a function is called? 

The moment the control of the program reads the function statement, it leaves the current section and shifts to first line of the called function.  

Let’s understand the flow of control in a function.  

Step1: The program reads the function call. 

Step2: The control searches the function and then shifts to the first line of that called function. 

Step3: All the statements/instructions are executed sequentially from top to bottom.  

Step4: After the last statement, the control again shifts back to the origin point (calling function) from where it started.  

Step5: If the function was designed to return a value, the control takes the value along with it to the primary program from where it started.  

There are mainly two types of functions: 

1). Built-in functions 

Built-in functions are those functions that are already defined in the existing libraries of the programming language. 

For example: Consider C language, printf() and scanf() are two inbuilt functions defined in the library stdio.h. 

Where printf() sends everything which is passed as arguments to the console screen to be displayed, scanf() is responsible for scanning a user input. 

While printf() does not returns any value, scanf() returns whatever input is given by user using a keyboard as “return value”. 

2). User-defined functions  

Here the functions are defined by the programmer or the coder to make the program optimized and modular.  

It may happen that the code might be required to expand somewhere in the future, functions take the charge of everything.  

It’s easier to scale the program with the help of functions; else it would be a daunting task and make the code look clumsy and cluttered.  

Let’s see how functions are defined:  

Defining a Function 

In C language, the general syntax of a program is: 

return_type name_of_function ( arguments ) { 

statments_to_executed (body of the function) 

return (expr); 

} 

Understanding parts of the function:  

  1. Return_type : It defines the datatype of the value or expression that the function would be returning. If the function is not made to return a value, then it’s the return_type is “void”. 
  2. Name of the function: It’s the name of the function. Name the function using the variable naming conventions used in that program. Function name along with the arguments make the signature of the function. 
  3.  Arguments : Arguments are the parameters that act as the palceholders for the values that are passed from the primary function.  These are optional. 
  4. Body of the function: This is the main part where all the statements are executed to achieve a desired goal. 
  5. Return: In case the function needs to return a value, it is return using this statement.  

For example:  

If you plan to make a calculator using a C code, you may have initially planned for just basic functions such as addition, subtraction, multiplication and division.  

Using the same in code is easy and can be done by simple using switch statements. 

But in case, you want to expand you code in future and would like to add some more operations such as trigonometry or logarithms, using functions makes the things sorted.   

You can easily make function declarations such as: 

int add( int a,int b );   // for addition 

int subs( int a ,int b);   // for subtraction  

int mult( int a ,int b);   // for multiplication 

int divide( int a ,int b);   // for division  

float logs( float a ,float b);   // for logarithm  

float trigno( float a ,float b);   // for trigonometric function  

 

Things to consider before writing the function  

  • Understand the need of the function. (Think from reusability, modularity and optimization point of view). 
  • Set the parameters and decide their datatypes. 
  • Work on the algorithm.      

The functions can call other functions and even themselves (recursion).  

Make sure to go more sensibly with the functions. Do not keep on creating functions unnecessarily that call other functions, which further call some more. 

The reason is whenever the program control reads the function, it pauses the current program to make the called function run. 

The main program is held in the active memory. So, if more functions are called within the functions, memory consumption increases. 

This turns out to be a real bad programming tactic. You need to be very careful while using functions as a slight blip may make your program go out of hand.  

 

Read More – Coding and Programing Questions

View More – Useful links for Your Child’s Development 

Why HTML is important to learn programming?

HTML is the language of the Internet. Without it, the digital world lacks existence. 

Whether you are planning to take up a career in web development or planning to launch your own website, knowledge of HTML is absolutely necessary. 

What is HTML? 

HTML, or HyperText Markup Language, is one of the primary three languages that is used to build every single website that you see on the internet.  

It defines the structure of the website such as how to place the things correctly like images, text, banners etc on a web page.  

Why it is important to learn HTML for programming? 

Learning HTML opens the gateways for one of the most highly demanded professionals in the industry today i.e. web developers and front end developers.  

No, matter which coding language you are using, PHP or JavaScript, at the end, everything gets converted into HTML to render a best view to the users.  

  • HTML is the past, present and future of internet 

HTML and CSS is the oldest and still stand irreplaceable in the web programming languages.  

Without these, there will be no websites. 

HTML gives the students a clear insight on how internet works and how to reach the audience is a best possible way.  

Understanding HTML makes the student understand the working and building of websites.  

There is no life without internet today. So, HTML is very crucial to learn in today’s scenario. 

  • HTML makes your learn other languages faster  

Since, HTML is the basic markup language, this helps you to understand other programming languages in a better way. 

HTML makes you understand the importance of tags and syntax, which is a vital when you learn any other programming language.  

Be it software or web programming, understanding HTML gives you an idea how the control flows step by step. 

  • Debugging made easier 

There is no point in learning any language of you don’t know how to debug the code.  

Since, HTML offers a simple interface, the concept of debugging becomes more clear. 

It’s easy to spot the errors when you visualize and debug the code to make it run more smoothly and effectively. 

  • Learn the basics of functions  

Functions are nothing but a basic block of code that performs a particular function and helps to maintain the cleanliness of the code. 

CSS does the same thing. Rather than writing the same formatting technique again and again, CSS helps the user to define all the formatting statements under one heading or “id”.  

HTML uses that “id” in its tags and the CSS gets loaded there in the run time. 

  • Fundamentals of Algorithms 

Algorithm or the flow chart of the problem is critical for developing any project. 

HTML helps you grab some basic fundamentals of algorithms.  

While designing the web page you need to track a lot of options such as navigation, menu items, hyperlinks, what happens when a person clicks the form etc. 

All these things form the basics of algorithms. A student learns how to plot the sequence of events and what will happen next. 

And this all what an algorithm does for any program. 

  • Learn different CMS 

Once you know the HTML, working with any kind of CMS or Content Management System is fun.  

You need to have little technical skills and the basic understanding of HTML, if you want to go creative with page creation strategies.  

HTML makes you learn and understand how the things exactly work in a CMS and makes your troubleshooting easier.  

So, HTML is here to stay and there is no internet or website without HTML.  

So, if you want to learn JavaScript, CSS, PHP or Angular JS effectively, start learning HTML today.  

 

Read More – Coding and Programing Questions

View More – Useful links for Your Child’s Development 

What are the types of HTML tags?

HTML is a simple and easy programming language used to create a website structure usually accompanied by CSS and JavaScript.  

When an HTML file is loaded in the browser, it reads all the contents written in the file and displays them on the screen with all visual elements properly placed.  

And what is that thing responsible for making the things appear structured and organized, it’s the HTML Tags.  

HTML Tags are special keywords used in the code and are written using angle brackets.  

Introduction to HTML Tags 

HTML Tags are like instructions that are embedded in the code and direct the browser do display the things in the instructed manner rather than displaying just the content. 

There are mainly three types of tags: 

1). Paired and Unpaired Tags 

Paired tags 

HTML Tags are known as paired tags when they come in pairs i.e. an opening tag and a closing tag.  

The paired tags starts with an opening tag written in angular brackets (< & >) and the tag name is enclosed in these brackets.  

The closing tag is written in the same way by just adding a slash in the front.   

For example: <b> This tag is used to mark that the content following will be written in bold till a closing tag is encountered which is </b> 

Example #1: 

<b> This text will be written in Bold. </b> 

 Output will be  

This text will be written in Bold. 

Here, <b> is opening tag and </b> is closing tag. 

More examples include: 

<html> </html>, <form> </form>, <h1> </h1>, <div> </div> 

Unpaired Tags 

The tags that do not have any closing tag or companion tag are called unpaired tags.  They just have an opening tag. 

These are also known as singular tags or standalone tags.   

Example: <hr> (used to draw a horizontal line), <br> (introduce a line break), <meta> (include meta information), <input> (introduce input fields) 

2). Self-Closing Tags 

These tags don’t have partner tags as they are self sufficient. Here the opening tag itself is required for the formatting.  

All the desired information is about its attributes is enclosed within the tag itself. 

<img> tag is one of the best examples of self-closing tag. 

<img src=”tags.jpeg” alt=” alternate text for this image”> 

More examples of self-closing tags include: 

<area />, <base />, <col />, <embed />, <link />  

 In older versions of HTML, the ending of the tag was accompanied by a forward slash such as  

<img src=”tags.jpeg” alt=” alternate text for this image” /> 

These are also known as void tags.  

Points to remember: 

  • In HTML 5: the slash is optional. 
  • In XHTML: Slash is required. 
  • In the previous version of HTML i.e. HTML4- the slash was technically not acceptable. However, W3C’s HTML Validator supported it.  

3). Utility-Based Tags 

Here the tags are differentiated on the basis of their utility or function. They are further divided into three categories.  

  • Formatting Tags 

These HTML tags help in formatting the text such as changing the size of text, changing to paragraphs, bold, italics, fonts etc.  

Tables, span and division tags also fall under this category as they play a crucial role in formatting the web page or document and decide the layout.   

Examples: 

<i> the text is italics </i> 

<table> here starts the table </table> 

Other examples include: 

<div> </div>, <u> </u>, <p> </p>, <b> </b> etc  

  • Structure Tags 

These tags are responsible for giving structure to the HTML document. The commonly used tags that you see in almost every HTML page come under structure tags. 

These tags have nothing to do with the formatting of the text, rather they help to build the document from the root.  

 For example:  

Structural Tags 
<html> </html>  It is the primary tag. It tells the browser that everything inside this tag is HTML code. 
<head> </head>  It contains all the meta things of the document and distinguishes head from rest of the body. The CSS/JS (javaScript) code or file is put here along with other meta data.  
<title> </title>  The content written inside this tag is displayed on the browser tab.  
<body </body>  All the actual content of the web-page is written here.  
<!DOCTYPE>  This tag tells us the document type declaration (DTD) and is accompanied by the word html. It helps the browser the type of file and to detect the content of the file appropriately.   

 

  • Control Tags 

These tags are responsible for managing the content on the web page. These tags also help in managing scripts or any external libraries they are added to the HTML during run-time.  

The entire drop down lists, form tags, input boxes etc that are used to interact with the user fall under this category.  

Here is a list of newly added tags in HTML 5 

Newly Added Tags in HTML 5 
<video>  This tag is used to lay a video file. 
<audio>  Audio files are embedded using this tag.  
<section>  A section in a document is defined using this HTML tag. 
<svg>  Used to display shapes 
<nav>  Define a navigation link 
<header>  Defines header section of the document 
<footer>  Defined the footer section of the document 
<dialog>  Defines a dialog box or a window 

 

Read More – Coding and Programing Questions

View More – Useful links for Your Child’s Development 

What is HTML?

HTML stands for Hyper Text Markup Language. It’s the language for designing websites and web pages.  

This language comprises of a set of markup symbols or small pieces of codes that are inserted in the file. These markups are indented to control the presentation of a webpage on the browser.  

Every website, be it social media, banking or music services are made by using HTML as the base language. 

 A deep peep into the code of the page will reveal the HTML Code written using the proper structures such as header, footer, body and other inline elements. 

What is the purpose of HTML? 

HTML is just another programming language that helps in describing the structure of the information that will be displayed on a web page.  

There are three essential building blocks of any webpage: HTML, CSS and JavaScript.    

While HTML gives the structure, CSS controls the appearance and JavaScript programming makes the web page dynamic by giving desired functionality.   

In other words we can put that, HTML is the skeleton system, CSS is the skin and JavaScript is the brain.  

People working on HTML and building websites are known as web developers or front-end developers.  

Every markup element is written in angular brackets “<” for opening and “>” for closing. These are also known as tags. Most of these tags come in pairs, one to mark the beginning and one to mark the end.  

History of HTML 

HTML was first developed in 1990 by Tim Berners-Lee. It was used to develop electronic pages that were displayed on www (World Wide Web).  

A webpage is connected to the other page using a hyperlink. The initial version was known as HTML 1.0.  

Over the years, as the technology progressed, HTML kept on improving and became stronger and secure. HTML 5.0 is the latest version that is being used across the globe for standard web development projects.  

HTML Explained 

In a nutshell, HTML is the programming language that helps in creation of web pages. Thus, leading to website development.  

The tags, elements and pneumonic used in HTML are very easy to comprehend as they follow very simple English. HTML continues to meet the ever changing needs and demand of the internet by following the protocols set by World Wide Web Consortium.  

Hyper means that the language is not linear, it’s dynamic. This makes the user access the web page with the same appearance from anywhere across the world and from any browser.  

Markup stands for the tags and elements that help in proper positioning of the text and images. For example you can use a <b> tag to make the text bold and <i> tag to change the text to italics.  

How HTML Works? 

HTML is just like short-codes that are typed and saved in a file with extension as .html or .htm. These tags empower the functionality of the HTML. 

These tags and the text typed in an editor will look simple unless it is opened in a browser. It’s the browser that interprets and read the file and convert into a visible form, something that we see in a website. 

To do the coding, you need to get an editor. There are many versions of editors available online. Grab a one and start your way to digital world.  

HTML vs. XML 

XML stands for Extensible Markup Language. Just like in HTML there are predefined tags, XML enables the user to define their own tags and markups.    

Why learn HTML? 

  • Very easy to learn, use and implement. 
  • The language is Platform-independent. 
  • Can add audio, video, text etc to a webpage by using correct tags. 
  • Best way to enter digital world as it helps developing websites and is supported by all browsers. 
  • Great career opportunities and professional growth.  

Read More – Coding and Programing Questions

View More – Useful links for Your Child’s Development 

Tel Guru
Tel Guru

Register For The Demo Class

[footer-form]