Computer Languages Classification
Computer Languages Classification
Over the years, computer languages have been evolved from Low-Level to High-Level Languages. In the
earliest days of computers, only Binary Language was used to write programs. The computer languages
are classified as follows...
Low-Level language is the only language which can be understood by the computer. Binary Language is
an example of a low-level language. Low-level language is also known as Machine Language. The binary
language contains only two symbols 1 & 0. All the instructions of binary language are written in the form
of binary numbers 1's & 0's. A computer can directly understand the binary language. Machine language
is also known as the Machine Code.
As the CPU directly understands the binary language instructions, it does not require any translator. CPU
directly starts executing the binary language instructions and takes very less time to execute the
instructions as it does not require any translation. Low-level language is considered as the First
Generation Language (1GL).
Advantages
Low-level language instructions require very less time for their execution.
Disadvantages
Low-level language instructions are machine-dependent, that means a program written for a
particular machine does not execute on another machine.
In low-level language, there is more chance for errors and it is very difficult to find errors, debug
and modify.
Middle-level language is a computer language in which the instructions are created using symbols such
as letters, digits and special characters. Assembly language is an example of middle-level language. In
assembly language, we use predefined words called mnemonics. Binary code instructions in low-level
language are replaced with mnemonics and operands in middle-level language. But the computer
cannot understand mnemonics, so we use a translator called Assembler to translate mnemonics into
binary language. Assembler is a translator which takes assembly code as input and produces machine
code as output. That means, the computer cannot understand middle-level language, so it needs to be
translated into a low-level language to make it understandable by the computer. Assembler is used to
translate middle-level language into low-level language.
Advantages
Disadvantages
Middle-level language is specific to a particular machine architecture, that means it is machine-
dependent.
High-Level Language
A high-level language is a computer language which can be understood by the users. The high-level
language is very similar to human languages and has a set of grammar rules that are used to make
instructions more easily. Every high-level language has a set of predefined words known as Keywords
and a set of rules known as Syntax to create instructions. The high-level language is easier to understand
for the users but the computer can not understand it. High-level language needs to be converted into
the low-level language to make it understandable by the computer. We use Compiler or interpreter to
convert high-level language to low-level language.
Languages like COBOL, FORTRAN, BASIC, C, C++, JAVA, etc., are examples of high-level languages. All
these programming languages use human-understandable language like English to write program
instructions. These instructions are converted to low-level language by the compiler so that it can be
understood by the computer.
Advantages
The programs created using high-level language runs on different machines with little change or
no change.
Disadvantages
The following figure provides a few key points related to computer languages.
From the above figure, we can observe the following key points...
The programming languages like C, C++, Java, etc., are written in High-level language which is
more comfortable for the developers.
Low-level language is closer to the computer. Computer hardware can understand only the low-
level language (Machine Language).
The program written in the high-level language needs to be converted to low-level language to
make communication between the user and the computer.
Middle-level language is not closer to both user and computer. We can consider it as a
combination of both high-level language and low-level language.
Compilers and interpreters
Both compilers and interpreters are the language processors used to convert software codes written in
high-level language into machine language codes. Compilers and interpreters are types of system
software. They are required because a computer cannot process a code written in high-level
programming language like C, C++, Java, etc. Therefore, we convert a HLL code into machine code for
execution.
In this article, we will highlight all the major differences between a compiler and an interpreter. Let's
start with some basics so that it will become easier to understand their differences.
What is a Compiler?
A language processor that converts a program written in high-level language into machine language,
entire program at once, is called a compiler. Thus, the input of a compiler is a high-level language code
(called source code), while its output is a machine language code (called object code).
A compiler scans whole program and then check it for syntactic and semantic error, once the code is
checked for errors, it is converted into an object code. Then, it can be processed by the machine to
perform the corresponding task. The common programming languages that use compiler are C, C++, C#,
etc.
Advantages of Compiler
What is an Interpreter?
A language translator that converts a high-level language program into a machine language program,
one line at a time, is referred to as an interpreter. Interpreters converts the codes slower than compiler.
This is because the interpreter can scan and translate only one statement of the program at a time.
Therefore, interpreters convert the source code into machine code during the execution of the program.
Interpreters do not generate an object code corresponding to the source code. However, these are
relatively easy to use and execute the code. The programming languages that use interpreters are Perl,
Ruby, Python, METLAB, etc.
Advantages of Interpreter
It is flexible.
The following table highlights all the significant differences between a Compiler and an Interpreter −
Program Compilers scan the entire program in one The program is interpreted/translated one line at a time.
scanning go.
Error detection As and when scanning is performed, all the One line of code is scanned, and errors encountered are
errors are shown in the end together, not shown.
line by line.
Object code Compilers convert the source code to object Interpreters do not convert the source code into object
code. code.
Execution time The execution time of compiler is less, hence It is not preferred due to its slow speed. Usually,
it is preferred. interpreter is slow, and hence takes more time to execute
the object code.
Need of source Compiler doesn’t require the source code for It requires the source code for execution later.
code execution later.
Programming Programming languages that use compilers Programming languages that uses interpreter include
languages include C, C++, C#, etc.. Python, Ruby, Perl, MATLAB, etc.
Types of errors Compiler can check syntactic and semantic Interpreter checks the syntactic errors only.
detected errors in the program simultaneously.
Conclusion
The most significant difference between a compiler and an interpreter is that a compiler scans the entire
program in one go, while an interpreter scans the program line by line. However, both are used in
different applications depending on the requirements of the programming language.
C programming
C programming is a general-purpose, procedure-oriented programming language. It is both machine-
independent and structured. C is a high-level programming language developed by Dennis Ritchie in the
early 1970s. It is now one of the most popular and influential programming languages worldwide. C is
popular for its simplicity, efficiency, and versatility, it has powerful features including low-level memory
access, a rich set of operators, and a modular framework. Apart from its importance with respect to
evolution of computer programming technologies, the design of C language has a profound influence on
most of the other programming languages that are in use today.
The languages that are influenced by C include Java, PHP, JavaScript, C#, Python and many more. These
languages have designed their syntax, control structures and other basic features from C.
C supports and run on different hardware and operating systems due to its portability.
Following are the applications and software used to create and execute C programs.
1. Turbo C
2. Turbo C++
3. GNU C
4. Code Blocks
5. Net Beans
C Tokens
Every C program is a collection of instructions and every instruction is a collection of some individual
units. Every smallest individual unit of a c program is called token. Every instruction in a c program is a
collection of tokens. Tokens are used to construct c programs and they are said to the basic building
blocks of a c program.
2. Identifiers
3. Operators
4. Special Symbols
5. Constants
6. Strings
7. Data values
In a C program, a collection of all the keywords, identifiers, operators, special symbols, constants,
strings, and data values are called tokens.
C Character Set
As every language contains a set of characters used to construct words, statements, etc., C language
also has a set of characters which include alphabets, digits, and special symbols. C language supports a
total of 256 characters.
Every C program contains statements. These statements are constructed using words and these words
are constructed using characters from C character set. C language character set contains the following
set of characters...
1. Alphabets
2. Digits
3. Special Symbols
Alphabets
C language supports all the alphabets from the English language. Lower and upper case letters
together support 52 alphabets.
Digits
C language supports 10 digits which are used to construct numerical values in C language.
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols
C language supports a rich set of special symbols that include symbols to perform mathematical
operations, to check conditions, white spaces, backspaces, and other special symbols.
Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , < \ | tab newline space NULL bell
backspace verticaltab etc.,
Every character in C language has its equivalent ASCII (American Standard Code for Information
Interchange) value.
C Keywords
As every language has words to construct statements, C programming also has words with a specific
meaning which are used to construct c program instructions. In the C programming language,
keywords are special words with predefined meaning. Keywords are also known as reserved words in
C programming language.
In the C programming language, there are 32 keywords. All the 32 keywords have their meaning which
is already known to the compiler.
Keywords are the reserved words with predefined meaning which already known to the compiler
Properties of Keywords
1. All the keywords in C programming language are defined as lowercase letters so they must be
used only in lowercase letters
2. Every keyword has a specific meaning, users can not change that meaning.
3. Keywords can not be used as user-defined names like variable, functions, arrays, pointers,
etc...
The following table specifies all the 32 keywords with their meaning...
C Identifiers
In C programming language, programmers can specify their name to a variable, array, pointer, function,
etc... An identifier is a collection of characters which acts as the name of variable, function, array,
pointer, structure, etc... In other words, an identifier can be defined as the user-defined name to
identify an entity uniquely in the c programming language that name may be of the variable name,
function name, array name, pointer name, structure name or a label.
The identifier is a user-defined name of an entity to identify it uniquely during the program execution
Example
int marks;
char studentName[30];
1. An identifier can contain letters (UPPERCASE and lowercase), numerics & underscore symbol
only.
2. An identifier should not start with a numerical value. It can start with a letter or an underscore.
3. We should not use any special symbols in between the identifier even whitespace. However, the
only underscore symbol is allowed.
5. There is no limit for the length of an identifier. However, the compiler considers the first 31
characters only.
The following are the commonly used rules for creating identifiers for better programming...
3. We start every identifier with a lowercase letter. If an identifier contains more than one word
then the first word starts with a lowercase letter and second word onwards first letter is used as
an UPPERCASE letter. We can also use an underscore to separate multiple words in an identifier.
C data types
Data used in c program is classified into different types based on its properties. In the C programming
language, a data type can be defined as a set of values with similar characteristics. All the values in a
data type have the same properties.
Data types in the c programming language are used to specify what kind of value can be stored in a
variable. The memory size and type of the value of a variable are determined by the variable data type.
In a c program, each variable or constant or array must have a data type and this data type specifies how
much memory is to be allocated and what type of values are to be stored in that variable or constant or
array. The formal definition of a data type is as follows...
The Data type is a set of value with predefined characteristics. data types are used to declare variable,
constants, arrays, pointers, and functions.
The primary data types in the C programming language are the basic data types. All the primary data
types are already defined in the system. Primary data types are also called as Built-In data types. The
following are the primary data types in c programming language...
The integer data type is a set of whole numbers. Every integer value does not have the decimal value.
We use the keyword "int" to represent integer data type in c. We use the keyword int to declare the
variables and to specify the return type of a function. The integer data type is used with different type
modifiers like short, long, signed and unsigned. The following table provides complete details about the
integer data type.
Floating Point data types
Floating-point data types are a set of numbers with the decimal value. Every floating-point value must
contain the decimal value. The floating-point data type has two variants...
float
double
We use the keyword "float" to represent floating-point data type and "double" to represent double data
type in c. Both float and double are similar but they differ in the number of decimal places. The float
value contains 6 decimal places whereas double value contains 15 or 19 decimal places. The following
table provides complete details about floating-point data types.
The following table provides complete information about all the data types in c programming language...
The void data type means nothing or no value. Generally, the void is used to specify a function which
does not return any value. We also use the void data type to specify empty parameters of a function.
An enumerated data type is a user-defined data type that consists of integer constants and each integer
constant is given a name. The keyword "enum" is used to define the enumerated data type.
Derived data types
Derived data types are user-defined data types. The derived data types are also called as user-defined
data types or secondary data types. In the c programming language, the derived data types are created
using the following concepts...
Arrays
Structures
Unions
Enumeration
C Variables
Variables in a c programming language are the named memory locations where the user can store
different values of the same datatype during the program execution. That means a variable is a name
given to a memory location in which we can store different values of the same data type. In other
words, a variable can be defined as a storage container to hold values of the same datatype during the
program execution. The formal definition of a data type is as follows...
Variable is a name given to a memory location where we can store different values of the same
datatype during the program execution.
Every variable in c programming language must be declared in the declaration section before it is used.
Every variable must have a datatype that determines the range and type of values be stored and the size
of the memory to be allocated.
A variable name may contain letters, digits and underscore symbol. The following are the rules to specify
a variable name...
3. A variable name should not contain any special symbols except underscore(_).
4. A variable name can be of any length but compiler considers only the first 31 characters of the
variable name.
Declaration of Variable
Declaration of a variable tells the compiler to allocate the required amount of memory with the
specified variable name and allows only specified datatype values into that memory location. In C
programming language, the declaration can be performed either before the function as global variables
or inside any block or function. But it must be at the beginning of block or function.
Declaration Syntax:
datatype variableName;
Example
int number;
The above declaration tells to the compiler that allocates 2 bytes of memory with the name number and
allows only integer values into that memory location.
C Constants
In C programming language, a constant is similar to the variable but the constant hold only one value
during the program execution. That means, once a value is assigned to the constant, that value can't be
changed during the program execution. Once the value is assigned to the constant, it is fixed throughout
the program. A constant can be defined as follows...
A constant is a named memory location which holds only one value throughout the program
execution.
In C programming language, a constant can be of any data type like integer, floating-point, character,
string and double, etc.,
Integer constants
An integer constant can be a decimal integer or octal integer or hexadecimal integer. A decimal integer
value is specified as direct integer value whereas octal integer value is prefixed with 'o' and hexadecimal
value is prefixed with 'OX'.
An integer constant can also be unsigned type of integer constant or long type of integer constant.
Unsigned integer constant value is suffixed with 'u' and long integer constant value is suffixed with 'l'
whereas unsigned long integer constant value is suffixed with 'ul'.
Example
A floating-point constant must contain both integer and decimal parts. Some times it may also contain
the exponent part. When a floating-point constant is represented in exponent form, the value must be
suffixed with 'e' or 'E'.
Example
The floating-point value 3.14 is represented as 3E-14 in exponent form.
Character Constants
A character constant is a symbol enclosed in single quotation. A character constant has a maximum
length of one character.
Example
'A'
'2'
'+'
In the C programming language, there are some predefined character constants called escape
sequences. Every escape sequence has its own special functionality and every escape sequence is
prefixed with '\' symbol. These escape sequences are used in output function called 'printf()'.
String Constants
A string constant is a collection of characters, digits, special symbols and escape sequences that are
enclosed in double quotations.
We can also define string constant by separating it with white space as follows...
"This" "is" "btechsmartclass"
Creating constants in C
We create a constant of any datatype using 'const' keyword. To create a constant, we prefix the variable
declaration with 'const' keyword.
The general syntax for creating constant using 'const' keyword is as follows...
Example
const int x = 10 ;
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i = 9 ;
const int x = 10 ;
i = 15 ;
The above program gives an error because we are trying to change the constant variable value (x = 100).
We can also create constants using '#define' preprocessor directive. When we create constant using this
preprocessor directive it must be defined at the beginning of the program (because all the preprocessor
directives must be written before the global declaration).
We use the following syntax to create constant using '#define' preprocessor directive...
Example
#define PI 3.14
Example Program
#include<stdio.h>
#include<conio.h>
#defien PI 3.14
void main(){
int r, area ;
scanf("%d", &r) ;
area = PI * (r * r) ;
C Storage Classes
In C programming language, storage classes are used to define things like storage location (whether
RAM or REGISTER), scope, lifetime and the default value of a variable.
In the C programming language, the memory of variables is allocated either in computer memory (RAM)
or CPU Registers. The allocation of memory depends on storage classes.
In C programming language, there are FOUR storage classes and they are as follows...
The default storage class of all local variables (variables declared inside block or function) is auto storage
class. Variable of auto storage class has the following properties...
Property Description
Keyword auto
Life time Till the control remains within the block in which variable is defined
Example Program 1
#include<stdio.h>
#include<conio.h>
int main(){
int i;
auto char c;
float f;
return 0;
Example Program 2
#include<stdio.h>
#include<conio.h>
int main(){
int a=10;
int a=20;
printf("%d",a);
printf(" %d",a);
return 0;
Example Program 3
#include<stdio.h>
#include<conio.h>
int main(){
int a=20;
printf("%d",a);
return 0;
The default storage class of all global varibles (variables declared outside function) is external storage
class. Variable of external storage class has the following properties...
Property Description
Keyword extern
Life time As long as the program’s execution does not comes to end
Example Program 1
#include<stdio.h>
#include<conio.h>
int main(){
printf("%d",i);
return 0;
Example Program 2
#include<stdio.h>
#include<conio.h>
int main(){
printf("%d",i);
return 0;
The static storage class is used to create variables that hold value beyond its scope until the end of the
program. The static variable allows to initialize only once and can be modified any number of times.
Variable of static storage class has the following properties...
Property Description
Keyword static
Property Description
Default Zero
Value
Life time The value of the persists between different function calls (i.e., Initialization is done
only once)
Example Program 1
#include<stdio.h>
#include<conio.h>
static int a;
int main(){
printf("%d",a);
return 0;
Example Program 2
#include<stdio.h>
#include<conio.h>
int main(){
printf("%d",i);
return 0;
}
Register storage class
The register storage class is used to specify the memory of the variable that has to be allocated in CPU
Registers. The memory of the register variable is allocated in CPU Register but not in Computer memory
(RAM). The register variables enable faster accessibility compared to other storage class variables. As
the number of registers inside the CPU is very less we can use very less number of register variables.
Variable of register storage class has the following properties...
Property Description
Keyword register
Life time Till the control remains within the block in which variable is defined
Example Program 1
#include<stdio.h>
#include<conio.h>
int main(){
scanf("%d%d",&a,&b);
printf("%d %d",a,b);
Automatic auto Computer Garbage Local to the block Till the control remains
Memory Value in which the within the block in which
(RAM) variable has variable is defined
defined
Static static Computer Zero Local to the block The value of the persists
Memory in which the between different function
(RAM) variable has calls (i.e., Initialization is
defined done only once)
Register register CPU Register Garbage Local to the block Till the control remains
Value in which the within the block in which
variable has variable is defined
defined
C Output Functions
C programming language provides built-in functions to perform output operation. The output operations
are used to display data on user screen (output screen) or printer or any file. The c programming
language provides the following built-in output functions...
1. printf()
2. putchar()
3. puts()
4. fprintf()
printf() function
The printf() function is used to print string or data values or a combination of string and data values on
the output screen (User screen). The printf() function is built-in function defined in a header file called
"stdio.h". When we want to use printf() function in our program we need to include the respective
header file (stdio.h) using the #include statement. The printf() function has the following syntax...
Syntax:
printf("message to be display!!!");
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
Output:
In the above example program, we used the printf() function to print a string on to the output screen.
The printf() function is also used to display data values. When we want to display data values we
use format string of the data value to be displayed.
Syntax:
printf("format string",variableName);
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i = 10;
float x = 5.5;
printf("%d %f",i, x);
Output:
In the above example program, we used the printf() function to print data values of variables i and x on
to the output screen. Here i is a an integer variable so we have used format string %d and x is a float
variable so we have used format string %f.
The printf() function can also be used to display string along with data values.
Syntax:
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i = 10;
float x = 5.5;
Output:
In the above program, we are displaying string along with data values.
Every function in the C programming language must have a return value. The printf() function also have
an integer as a return value. The printf() function returns an integer value equivalent to the total
number of characters it has printed.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i;
i = printf("btechsmartclass");
Output:
In the above program, first printf() function printing "btechsmartclass" which is of 15 characters. So it
returns integer value 15 to the variable "i". The value of "i" is printed in the second printf() function.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
printf("Welcome to ");
printf("btechsmartclass ");
Output:
In the above program, there are 3 printf() statements written in different lines but the output is
displayed in single line only.
To display the output in different lines or as we wish, we use some special characters called escape
sequences. Escape sequences are special characters with special functionality used in printf() function to
format the output according to the user requirement. In the C programming language, we have the
following escape sequences...
\a Beep sound
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
printf("Welcome to\n");
printf("btechsmartclass\n");
Output:
putchar() function
The putchar() function is used to display a single character on the output screen. The putchar() functions
prints the character which is passed as a parameter to it and returns the same character as a return
value. This function is used to print only a single character. To print multiple characters we need to write
multiple times or use a looping statement. Consider the following example program...
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
char ch = 'A';
putchar(ch);
Output:
puts() function
The puts() function is used to display a string on the output screen. The puts() functions prints a string or
sequence of characters till the newline. Consider the following example program...
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
char name[30];
gets(name);
puts(name);
Output:
fprintf() function
The fprintf() function is used with the concept of files. The fprintf() function is used to print a line into
the file. When you want to use fprintf() function the file must be opened in writting mode.
C Input Functions
C programming language provides built-in functions to perform input operations. The input operations
are used to read user values (input) from the keyboard. The c programming language provides the
following built-in input functions.
1. scanf()
2. getchar()
3. getch()
4. gets()
5. fscanf()
scanf() function
The scanf() function is used to read multiple data values of different data types from the keyboard. The
scanf() function is built-in function defined in a header file called "stdio.h". When we want to use scanf()
function in our program, we need to include the respective header file (stdio.h)
using #include statement. The scanf() function has the following syntax...
Syntax:
scanf("format strings",&variableNames);
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i;
scanf("%d",&i);
Output:
In the above example program, we used the scanf() function to read an integer value from the keyboard
and store it into variable 'i'.
The scanf function also used to read multiple data values of different or the same data types. Consider
the following example program...
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i;
float x;
scanf("%d%f",&i, &x);
Output:
In the above example program, we used the scanf() function to read one integer value and one float
value from the keyboard. Here 'i' is an integer variable so we have used format string %d, and 'x' is a
float variable so we have used format string %f.
The scanf() function returns an integer value equal to the total number of input values read using scanf
function.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i,a,b;
float x;
Output:
getchar() function
The getchar() function is used to read a character from the keyboard and return it to the program. This
function is used to read a single character. To read multiple characters we need to write multiple times
or use a looping statement. Consider the following example program...
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
char ch;
ch = getchar();
Output:
getch() function
The getch() function is similar to getchar function. The getch() function is used to read a character from
the keyboard and return it to the program. This function is used to read a single character. To read
multiple characters we need to write multiple times or use a looping statement. Consider the following
example program...
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
char ch;
ch = getch();
Output:
gets() function
The gets() function is used to read a line of string and stores it into a character array. The gets() function
reads a line of string or sequence of characters till a newline symbol enters. Consider the following
example program...
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
char name[30];
gets(name);
printf("%s",name);
Output:
fscanf() function
The fscanf() function is used with the concept of files. The fscanf() function is used to read data values
from a file. When you want to use fscanf() function the file must be opened in reading mode.
C Operators
An operator is a symbol used to perform arithmetic and logical operations in a program. That means an
operator is a special symbol that tells the compiler to perform mathematical or logical operations. C
programming language supports a rich set of operators that are classified as follows.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
5. Assignment Operators
6. Bitwise Operators
7. Conditional Operator
8. Special Operators
The arithmetic operators are the symbols that are used to perform basic mathematical operations like
addition, subtraction, multiplication, division and percentage modulo. The following table provides
information about arithmetic operators.
Operator Meaning Example
+ Addition 10 + 5 =
- Subtraction 10 - 5 =
* Multiplication 10 * 5 =
/ Division 10 / 5 =
⇒ The addition operator can be used with numerical data types and character data type. When it is used
with numerical values, it performs mathematical addition and when it is used with character data type
values, it performs concatination (appending).
⇒ The remainder of the division operator is used with integer data type only.
The relational operators are the symbols that are used to compare two values. That means the
relational operators are used to check the relationship between two values. Every relational operator
has two results TRUE or FALSE. In simple words, the relational operators are used to define conditions in
a program. The following table provides information about relational operators.
< Returns TRUE if the first value is smaller than second value otherwise returns FALSE 10 < 5 is
> Returns TRUE if the first value is larger than second value otherwise returns FALSE 10 > 5 is
<= Returns TRUE if the first value is smaller than or equal to second value otherwise returns FALSE 10 <= 5
>= Returns TRUE if the first value is larger than or equal to second value otherwise returns FALSE 10 >= 5
!= Returns TRUE if both values are not equal otherwise returns FALSE 10 != 5 i
The logical operators are the symbols that are used to combine multiple conditions into one condition.
The following table provides information about logical operators.
&& Logical AND - Returns TRUE if all conditions are TRUE otherwise 10 < 5 && 12 > 10 is
returns FALSE FALSE
|| Logical OR - Returns FALSE if all conditions are FALSE otherwise 10 < 5 || 12 > 10 is
returns TRUE TRUE
! Logical NOT - Returns TRUE if condition is FLASE and returns !(10 < 5 && 12 > 10) is
FALSE if it is TRUE TRUE
⇒ Logical AND - Returns TRUE only if all conditions are TRUE, if any of the conditions is FALSE then
complete condition becomes FALSE.
⇒ Logical OR - Returns FALSE only if all conditions are FALSE, if any of the conditions is TRUE then
complete condition becomes TRUE.
The increment and decrement operators are called unary operators because both need only one
operand. The increment operators adds one to the existing value of the operand and the decrement
operator subtracts one from the existing value of the operand. The following table provides information
about increment and decrement operators.
Pre-Increment or Pre-Decrement
In the case of pre-increment, the value of the variable is increased by one before the expression
evaluation. In the case of pre-decrement, the value of the variable is decreased by one before the
expression evaluation. That means, when we use pre-increment or pre-decrement, first the value of the
variable is incremented or decremented by one, then the modified value is used in the expression
evaluation.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i = 5,j;
j = ++i; // Pre-Increment
Output:
Post-Increment or Post-Decrement
In the case of post-increment, the value of the variable is increased by one after the expression
evaluation. In the case of post-decrement, the value of the variable is decreased by one after the
expression evaluation. That means, when we use post-increment or post-decrement, first the expression
is evaluated with existing value, then the value of the variable is incremented or decremented by one.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i = 5,j;
j = i++; // Post-Increment
Output:
The assignment operators are used to assign right-hand side value (Rvalue) to the left-hand side variable
(Lvalue). The assignment operator is used in different variants along with arithmetic operators. The
following table describes all the assignment operators in the C programming language.
Operator Meaning
+= Add both left and right-hand side values and store the result into left-hand side variable
-= Subtract right-hand side value from left-hand side variable value and store the result
into left-hand side variable
*= Multiply right-hand side value with left-hand side variable value and store the result
into left-hand side variable
/= Divide left-hand side variable value with right-hand side variable value and store the result
into the left-hand side variable
%= Divide left-hand side variable value with right-hand side variable value and store the remainder
into the left-hand side variable
The bitwise operators are used to perform bit-level operations in the c programming language. When
we use the bitwise operators, the operations are performed based on the binary values. The following
table describes all the bitwise operators in the C programming language.
Let us consider two variables A and B as A = 25 (11001) and B = 20 (10100).
Operator Meaning
& the result of Bitwise AND is 1 if all the bits are 1 otherwise it is 0
^ the result of Bitwise XOR is 0 if all the bits are same otherwise it is 1
Operator Meaning
<< the Bitwise left shift operator shifts all the bits to the left by the specified number of positions
>> the Bitwise right shift operator shifts all the bits to the right by the specified number of positions
The conditional operator is also called a ternary operator because it requires three operands. This
operator is used for decision making. In this operator, first we verify a condition, then we perform one
operation out of the two operations based on the condition result. If the condition is TRUE the first
option is performed, if the condition is FALSE the second option is performed. The conditional operator
is used with the following syntax.
Example
sizeof operator
This operator is used to find the size of the memory (in bytes) allocated for a variable. This operator is
used with the following syntax.
sizeof(variableName);
Example