PPS Unit-1
PPS Unit-1
PPS
What is Computer?
The term "computer" is derived from the Latin word "computare" which means to
calculate. A computer is an electronic device that can process and store information. It
can perform calculations, manipulate data, and execute instructions to accomplish
specific tasks. The basic components of a computer include the central processing unit
(CPU), memory, storage, input devices (keyboard, mouse, etc.), output devices (monitor,
printer, etc.), and various peripheral devices.
A computer is designed to execute applications and provides a variety of solutions
through integrated hardware and software components.
The basic parts without which a computer cannot work are as follows:
• Processor: It executes instructions from software and hardware.
• Memory: It is the primary memory for data transfer between the CPU and
storage.
• Motherboard: It is the part that connects all other parts or components of a
computer.
• Storage Device: It permanently stores the data, e.g., hard drive.
• Input Device: It allows you to communicate with the computer or to input data,
e.g., a keyboard.
• Output Device: It enables you to see the output, e.g., monitor.
1
II. Arithmetic And Logic Unit (ALU)6
III. Memory Unit
a) Primary memory
b) Secondary memory
3. Output Unit
1. Input Unit: The computer requires the input unit to receive data and information
and then use it to solve problems. The user provides the computer with data and
information. With the use of input devices, we give data and information input. The input
unit is made up of a variety of input devices. Some input devices are a keyboard, mouse,
microphone, scanner, etc.
The Input Unit’s Primary Functions Are As Follows:
1. With the use of input devices, collect data from the user.
2. Convert the data from electrical signals to computer-readable machine language.
3. Instruct the CPU to receive data from the input devices.
4. Provide the transformed data to the CPU through the memory unit for further
processing.
2
2. CPU – Central Processing Unit: Central Processing Unit or the CPU, is the
brain of the computer. It works the same way a human brain works. As the brain controls
all human activities, similarly the CPU controls all the tasks.
Moreover, the CPU conducts all the arithmetical and logical operations in the computer.
Now the CPU comprises of two units, namely – ALU (Arithmetic Logic Unit) and CU
(Control Unit). Both of these units work in sync. The CPU processes the data as a whole.
I. ALU – Arithmetic Logic Unit: The Arithmetic Logic Unit is made of two terms,
arithmetic and logic. There are two primary functions that this unit performs.
1. Data is inserted through the input unit into the primary memory. Performs the
basic arithmetical operations on it, like addition, subtraction, multiplication, and
division. It performs all sorts of calculations required on the data. Then, it sends
back data to the storage.
2. The unit is also responsible for performing logical operations like AND, OR,
Equal to, Less than, etc. In addition to this, it conducts merging, sorting, and
selection of the given data.
II. CU – Control Unit: The control unit as the name suggests is the controller of all the
activities/tasks and operations. All this is performed inside the computer.
The memory unit sends a set of instructions to the control unit. Then the control unit in
turn converts those instructions. After that these instructions are converted to control
signals. These control signals help in prioritizing and scheduling activities. Thus, the
control unit coordinates the tasks inside the computer in sync with the input and output
units.
III. Memory Unit: All the data that has to be processed or has been processed is
stored in the memory unit. The memory unit acts as a hub of all the data. It transmits it to
the required part of the computer whenever necessary.
The memory unit works in sync with the CPU. This helps in faster accessing and
processing of the data. Thus, making tasks easier and quicker.
Types of Computer Memory
There are two types of computer memory-
3
Primary Memory: This type of memory cannot store a vast amount of data. Therefore, it
is only used to store recent data. The data stored in this is temporary. It can get erased
once the power is switched off. Therefore, is also called temporary memory or main
memory.
RAM stands for Random Access Memory. It is an example of primary memory. This
memory is directly accessible by the CPU. It is used for reading and writing purposes.
For data to be processed, it has to be first transferred to the RAM and then to the CPU.
Secondary Memory: As explained above, the primary memory stores temporary data.
Thus it cannot be accessed in the future. For permanent storage purposes, secondary
memory is used. It is also called permanent memory or auxiliary memory. The hard disk
is an example of secondary memory. Even in a power failure data does not get erased
easily.
3. Output: There is nothing to be amazed by what the output unit is used for. All the
information sent to the computer once processed is received by the user through the
output unit. Devices like printers, monitors, projectors, etc. all come under the output
unit.
The output unit displays the data either in the form of a soft copy or a hard copy. The
printer is for the hard copy. The monitor is for the display. The output unit accepts the
data in binary form from the computer. It then converts it into a readable form for the
user.
4
CPU Operations
• Fetch: The processor usually gets instructions from RAM.
• Decode: A decoder translates an instruction into signals that the computer's other
parts can use.
• Execute: Each component receives the now-decoded instructions.
• Store: After the execute step the instructions are ready to store in the memory.
Types of Processors
• Single Core Processors: The oldest type of computer CPUs is single core CPU.
These CPUs were used in the 1970s. these CPUs only have a single core that
preform different operations. This means that the single core CPU can only
process one operation at a single time. single core CPU is not suitable for
multitasking.
• Dual-Core Processors: Dual-Core CPUs contain a single Integrated Circuit with
two cores. Each core has its cache and controller. These controllers and cache are
work as a single unit. dual core CPUs can work faster than the single-core
processors.
• Quad-Core Processors: Quad-Core CPUs contain two dual-core processors
present within a single integrated circuit (IC) or chip. A quad-core processor
contains a chip with four independent cores. These cores read and execute various
instructions provided by the CPU. Quad Core CPU increases the overall speed for
programs. Without even boosting the overall clock speed it results in higher
performance.
PROGRAMMING
What Is Programming?
Programming refers to a technological process for telling a computer which tasks to
perform in order to solve problems. It is collaboration between humans and computers.
And a program is a set of instructions telling a computer how to perform various tasks. A
programming language is used by programmers to create a program.
5
How does computer programming work?
At its most basic, programming tells a computer what to do. First, a programmer writes
code—a set of letters, numbers, and other characters. Next, a compiler converts each line
of code into a language a computer can understand. Then, the computer scans the code
and executes it, thereby performing a task or series of tasks. Tasks might include
displaying an image on a webpage or changing the font of a section of text.
6
What are High-Level Languages?
• One can easily interpret and combine these languages as compared to the low-
level languages.
• They are very easy to understand.
• Such languages are programmer-friendly.
• Debugging is not very difficult.
• They come with easy maintenance and are thus simple and manageable.
• One can easily run them on different platforms.
• They require a compiler/interpreter for translation into a machine code.
• A user can port them from one location to another.
• Such languages have a low efficiency of memory. So it consumes more memory
than the low-level languages.
• They are very widely used and popular in today’s times.
• Java, C, C++, Python, etc., are a few examples of high-level languages.
PROGRAMMING CONCEPTS
Fundamental programming concepts include a set of basic principles and related
terminologies that programmers follow to write code that is simple to understand,
modular, and efficient. Some common programming concepts are written in below-
1. Variable declaration: Variables are placeholders in memory that store data during the
program’s execution. They allow programmers to give names to memory locations,
making manipulating and managing data easier.
2. Control Structures: Control structures allow programmers to control the flow of a
program’s execution. They determine how and when certain blocks of code will be
executed based on certain conditions. The most common control structures include:
• Conditional Statements: These statements, such as if, else if, and else, allow the
program to execute different code blocks depending on whether certain conditions
are true or false.
• Loops: Loops enable the program to repeat a certain block of code multiple times,
making it easier to perform repetitive tasks.
7
4. Functions: The functions are the most important programming concept that allows
you to repeat instructions, without having the need to type those instructions again and
again when they are needed to be executed in the program.
5. Data structures: A data structure provides an effective way to store and retrieve data.
There are various data structures that computer programmers can use to complete tasks
and run applications. Some common data structures are: Arrays, linklist, graphs etc.
6. Object-oriented programming: Object-oriented programming is based on the
concept of objects and classes where an object may contain data in the form of attributes
and methods. For example, consider a class that represents a person. The person class
contains attributes such as name, date of birth, blood group, nationality, gender, and
height. You can then use this class as a blueprint to create objects.
7. Debugging: Debugging is the process of removing errors from computer programs
that allow software development and engineering teams to produce functioning software.
8. Input and Output: This is how your program interacts with the outside world. It's like
getting information from a user (input) and showing results (output).
9. Data Types: This is like a category for the information you're storing. There are
different types like numbers (like 1, 2.5), text (like "hello"), and more complex types.
1) Simplicity: A good programming language must be simple and easy to learn and
use.
2) User Friendly: A program that can be easily understood by a beginner is called
„user friendly‟.
3) Flexibility: A program should be flexible enough to handle most of the changes
without having to rewrite the entire program. For example, CAD software is use
for different purposes such as; engineering drafting, printing circuit board layout,
and design, architectural design, technical drawing, industrial art, etc.
4) Structuring: the language allows programmers to write their code according to
structured programming concepts to avoid creating errors.
8
5) Portability: Portability refers to the ability of an application to run on different
platforms (operating systems) with or without minimal changes.
6) Readability: Code should be written in a way that is easy for humans to
understand. This makes it easier for other programmers (or even the original
programmer after some time) to read and modify the code.
7) Maintainability: A program should be designed in a way that makes it easy to
update or modify. This includes adding new features, fixing bugs, or making
improvements without causing unintended side effects.
8) Scalability: A program should be able to handle an increasing amount of work or
data. It should be able to grow in size or capability as needed.
9
3. Algorithm Development: Here, we develop a step-by-step procedure that is used to
solve the problem by using the specification given in the previous phase. It is very
important phase for the program development. We write the solution in step-by-step
statements. Algorithm is the list of instructions in a particular order to solve the problem.
4. Coding & Documentation: Here, we use a programming language to write or
implement the actual programming instructions for the steps defined in the previous
phase. We construct the actual program in this phase. We write the program to solve the
given problem by using the programming languages like C, C++, Java, etc.
5. Testing & Debugging: In this phase, we check whether the written code in the
previous step is solving the specified problem or not. This means, we try to test the
program whether it is solving the problem for various input data values or not. We also
test if it is providing the desired output or not.
6. Maintenance: In this phase, we make the enhancements. Therefore, the solution is
used by the end-user. If the user gets any problem or wants any enhancement, then we
need to repeat all these phases from the starting, so that the encountered problem is
solved or enhancement is added.
ALGORITHM
An algorithm is a set of steps for solving a known problem. The formal definition of an
algorithm is that it contains the finite set of instructions which are being carried in a
specific order to perform the specific task. One common example of an algorithm is a
recipe, which consists of specific instructions for preparing a dish or meal.
10
Step 1: First, we will cut the lemon into half.
Step 2: Squeeze the lemon as much you can and take out its juice in a container.
Step 3: Add two tablespoon sugar in it.
Step 4: Stir the container until the sugar gets dissolved.
Step 5: When sugar gets dissolved, add some water and ice in it.
Step 6: Store the juice in a fridge for 5 to minutes.
Advantages of Algorithms:
1. It is easy to understand.
2. An algorithm is a step-wise representation of a solution to a given problem.
3. In an Algorithm the problem is broken down into smaller pieces or steps hence, it
is easier for the programmer to convert it into an actual program.
Disadvantages of Algorithms:
1. Writing an algorithm takes a long time so it is time-consuming.
2. Understanding complex logic through algorithms can be very difficult.
3. Branching and Looping statements are difficult to show in Algorithms.
11
PSEUDO CODE
Pseudocode is a simplified version of programming codes, written in plain English
language and used to outline a program before its implementation. it has no specific
syntax, it is easy to read and write.
12
4. For a beginner, It is more difficult to follow the logic or write pseudo code as
compared to flowchart.
Algorithm vs Pseudocode
BASIS OF
ALGORITHM PSEUDOCODE
COMPARISON
13
Algorithms can be used in any
complex programming language Pseudocodes are not used in any
Programming
as it uses simple logical code complex programming languages.
snippets.
FLOWCHARTS
Flowcharts are nothing but the graphical representation of the data or the algorithm for
a better understanding of the code visually. It displays step-by-step solutions to a
problem, algorithm, or process.
Symbols Used In Flowchart
14
Used to connect the
Off-page Connector flowchart portion on a
different page
SYMBOLS
Symbols in computer programming are primitive data types whose instances have a
unique human-readable form. In programming we use to called symbol as “operator”.
These symbols can be used as identifiers that have a specific purpose for each character.
There are several symbols used, but these are the basic symbols that used in programming:
15
Symbols Meaning/Uses
Not Equal to != checks two operands, returns True if they are not
equal
Single Quotes ‘ ’ and Double It is used to denote that you are writing a string
Quotes “ ” directly into the code.
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.
16
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.
Advantages of Compiler
• A compiler translates a program in a single run.
• It consumes less time.
• CPU utilization is more.
• Both syntactic and semantic errors can be checked concurrently.
• It is easily supported by many high-level languages like C, C++, JAVA, etc.
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.
The programming languages that use interpreters are Perl, Ruby, Python, METLAB, etc.
Advantages of Interpreter
• There are various advantages of the interpreter which are as follows −
• An interpreter translates the program line by line.
• The interpreter is smaller in size.
• It is flexible.
17
• Error localization is easier.
• The interpreter facilitates the implementation of computer programming language
constructs.
Error detection As and when scanning is One line of code is scanned, and errors
performed, all the errors are encountered are shown.
shown in the end together, not
line by line.
Object code Compilers convert the source Interpreters do not convert the source
code to object code. code into object code.
Execution time The execution time of It is not preferred due to its slow speed.
compiler is less, hence it is Usually, interpreter is slow, and hence
preferred. takes more time to execute the object
code.
Need of source Compiler doesn’t require the It requires the source code for execution
code source code for execution later.
later.
Types of errors Compiler can check syntactic Interpreter checks the syntactic errors
detected and semantic errors in the only.
program simultaneously.
18
Size Compiler are larger in size. Interpreters are smaller in size.
DEBUGGING
Debugging is the process of finding and fixing errors or bugs in the source code of any
software. When software does not work as expected, computer programmers study the
code to determine why any errors occurred. They use debugging tools to run the software
in a controlled environment, check the code step by step, and analyze and fix the issue.
Debugging can be a time-consuming and complex task, but it is essential for ensuring
that a software system is functioning correctly. There are several common methods and
techniques used in debugging, including code inspection, debugging tools, unit testing,
integration testing, system testing, monitoring, and logging. It is an iterative process that
may take multiple attempts to identify and resolve all bugs in a software system.
The debugging process typically involves three steps:
1. Identifying bugs. During the first stage of the debugging process, end users,
quality assurance (QA) testers, and developers report bugs. They may find these
problems through testing processes, reviewing lines of code, or simply by using
the software or device.
2. Analyzing bugs. At this phase, the reported bugs from step one will be evaluated.
Important elements to consider include how the bug impacts the functionality and
which parts of the software or hardware will be affected by it. The developers
then prioritize bug fixes and create an action plan and timeline for fixing.
3. Fixing bugs and preparing for the future. Once the bugs have been fixed,
developers and QA testers ensure the software will continue to work properly by
running tests. They also plan future tests to more easily identify recurring bugs.
19
Debugging vs. testing: What's the difference?
Testing is one part of the debugging process. Debugging involves correcting the issues
found during testing. QA testers and end users may test software, but developers typically
troubleshoot and resolve the reported errors to finish the debugging process.
Advantages of Debugging:
1. Improved system quality: By identifying and resolving bugs, a software system
can be made more reliable and efficient, resulting in improved overall quality.
2. Increased user satisfaction: By identifying and resolving bugs, a software
system can be made more user-friendly and better able to meet the needs of users,
which can result in increased satisfaction.
3. Reduced development costs: By identifying and resolving bugs early in the
development process, it can save time and resources that would otherwise be
spent on fixing bugs later in the development process or after the system has been
deployed.
4. Increased security: By identifying and resolving bugs that could be exploited by
attackers, a software system can be made more secure, reducing the risk of
security breaches.
5. Better understanding of the system: Debugging can help developers gain a
better understanding of how a software system works, and how different
components of the system interact with one another.
Disadvantages of Debugging:
1. Time-consuming: Debugging can be a time-consuming process, especially if the
bug is difficult to find or reproduce.
2. Requires specialized skills: Debugging can be a complex task that requires
specialized skills and knowledge.
3. Can be difficult to reproduce: Some bugs may be difficult to reproduce, which
can make it challenging to identify and resolve them.
4. Can be difficult to fix: Some bugs may be caused by fundamental design flaws
or architecture issues, which can be difficult or impossible to fix without
significant changes to the software system.
20
5. Can be expensive: Debugging can be an expensive process, especially if it
requires additional resources such as specialized debugging tools or additional
development time.
1. Syntax Errors
We can define these types of errors basically as grammatical errors. Like in any other
language, each programming language has its own set of rules and way of writing the
program. Moreover, these rules are per the grammar of each programming language.
Furthermore, if the programmer violates any of these rules this is the syntax error. These
errors can be as follows:
• Missing semicolons (;)
• unbalanced parenthesis ({})
• missing operators
• indentation
• error in the structure of the program
21
• Assigning value to a variable without declaring it
2. Runtime Error
These types of errors are detected during the runtime. Moreover, such errors cause
unusual termination of the program. Runtime errors can be a little tricky to identify
because the compiler can not detect these errors. They can only be identified once the
program is running. Some of the most common run time errors are: number not divisible
by zero, array index out of bounds, string index out of bounds, etc. Some examples of
such errors are as follows:
• dividing a number by 0
• infinite loop
• wrong input by the user
22
3. Linker Error
Linker is a program that takes the object files generated by the compiler and combines
them into a single executable file. Linker errors are the errors encountered when the
executable file of the code can not be generated even though the code gets compiled
successfully. This error is generated when a different object file is unable to link with the
main object file. We can run into a linked error if we have imported an incorrect header
file in the code, we have a wrong function declaration, etc.
In the above code, as we wrote Main() instead of main(), the program generated a linker
error. This happens because every file in the C language must have a main() function. As
in the above program, we did not have a main() function, the program was unable to run
the code, and we got an error. This is one of the most common type of linker error.
4. Logical Error
If your program is syntax free it will compile successfully. But, if the logic is incorrect it
is not necessary that you get the desired output. Therefore, such errors are logical or
23
semantic errors. Usually, such errors are indicated during run time. Since the program has
no syntax errors, therefore, it runs successfully. But, it is not necessary that you get the
expected output. Hence, in such cases, we have to check the program for logical errors.
Thus, we can say that logical error is a type of runtime error.
Example:
In this program logic, the user needs to check divisibility by 10. But, in the ‘if’ condition
instead of using ‘==’ it is ‘=’ which is the assignment operator. Therefore, we need the
‘==’ operator to check if the remainder is equal to 0 or not.
5. Semantic Error
Errors that occur because the compiler is unable to understand the written code are called
Semantic Errors. A semantic error will be generated if the code makes no sense to the
compiler, even though it is syntactically correct. It is like using the wrong word in the
wrong place in the English language. For example, adding a string to an integer will
generate a semantic error.
Semantic errors are different from syntax errors, as syntax errors signify that the structure
of a program is incorrect without considering its meaning. On the other hand, semantic
errors signify the incorrect implementation of a program by considering the meaning of
the program.
24
When we have an expression on the left-hand side of an assignment operator (=), the
program generates a semantic error. Even though the code is syntactically correct, the
compiler does not understand the code.
Variables in C
Variable is basically nothing but the name of a memory location that we use for storing
data. We can change the value of a variable in C or any other language, and we can also
reuse it multiple times. It allows us to refer to memory location without having to
memorize the memory address. We use symbols in variables for representing the memory
location- so that it becomes easily identifiable by any user.
The name of a variable can be a composition of digits, letters, and also underscore
characters. The name of the character must begin with either an underscore or a letter. In
25
the case of C, the lowercase and uppercase letters are distinct. It is because C is case-
sensitive in nature. Let us look at some more ways in which we name a variable.
OUTPUT:
Explanation: In the given program, a is a variable that serves as a name for a memory
location to store an integer value. It store the value 25 and later retrieve it for printing
without needing to reference its full memory address.
Syntax: In C, we have to declare the type of data the variable would store along with
the name while creating a variable:
This data type decides how much memory a variable need. We can choose the data
types provided by C language to store different type of data in the variable. Examples of
data types in C include int (integer), float (a floating-point number), char (character),
double (a double-precision floating-point number)
Variable name: It is the identifier for the variable, i.e., the name you give to the variable
to access its value later in the program. The variable name must follow specific rules, like
starting with a letter or underscore and consisting of letters, digits, and underscores
We can also create multiple variables in a single statement by separating them using
comma:
26
Where v1, v2 … are the names for variables.
Example
Here, a, b, and c are variables. The int , float, and char are the data types.
27
int my var; // it is incorrect – there must be no spaces in the name of the variable
int COUNT; // it is a new variable
int Count; // it is a new variable
int count; // it is a valid variable name
Types of Variables in C
There are many types of variables in c:
1. local variable
2. global variable
3. static variable
4. automatic variable
5. external variable
1. Local Variable in C: The variable that is declared in a function or code is called a
local variable. The scope of Local variables is within the defined function only. You
cannot use a local variable outside the function (in which it is declared).
OUTPUT
age is 20
height is 5.600000
28
2. Global Variables: The scope of the global variable is the entire program. They are
not defined inside any function and can be used in any function.
OUTPUT
The number is 23
The number is 23
3. Static Variable: The static variable is defined using the static keyword. Its scope
depends on the area of its declaration. If a static variable is defined within a function, it is
a local variable. If declared outside the function, its scope is global. A static variable
statically allocated memory to the variable and its lifetime throughout the program. It
holds its value whenever a program is called. The default value of the static variable is 0.
Syntax: static data_type variable_name = initial_value
29
OUTPUT
The value of local variable: 20
The value of Static variable: 30
Calling function 2nd time
The value of local variable: 20
The value of Static variable: 40
Calling function 3rd time
The value of local variable: 20
The value of Static variable: 50
NOTE: In the above program the value of the static variable is increasing by 10 every
time when the function is called. While the value of the local variable is the same as the
function call.
OUTPUT
The value of local variable: 10
The value of automatic variable: 20
30
5. Extern Variable: The extern variables use the extern keyword before the variable
definition. This enhances the variable visibility, and the variable can be used in different
C files. It is a global variable. It is not necessary to initialize the variable at the time of its
declaration. Its lifetime is the entire program.
Syntax: extern data_type variable_name;
6. Constant Variable: The constant variables are special variables in C whose value
does not change throughout the program after initialization. It is a read-only variable in
C. Initializing a constant variable at the time of variable declaration is mandatory. It uses
the “const” keyword before its definition.
We can initialize other variables anytime and anywhere in the program and can also
change their value. But constant variables have a fixed value, you cannot change their
value after their initialization. If you try to change the value of a constant variable, the
program will generate errors.
DATA TYPES
Unlike humans, a computer does not know the difference between "1234" and "abcd." A
data type is a classification that dictates what a variable or object can hold in computer
programming.
Common Data Types:
31
Types Description
Primitive Data Primitive data types are the most basic data types that are used for
Types representing simple values such as integers, float, characters, etc.
User Defined
The user-defined data types are defined by the user himself.
Data Types
These data types are formed by using basic data types i.e. using one or
Derived Types
more built-in data types.
32
1. Integer (int):- It is the most common numeric data type used to store numbers
without a fractional component (-707, 0, 707,123 etc).
2. Floating Point (float):- It is also a numeric data type used to store numbers that may
have a fractional component like monetary values do (707.07, 0.7, 707.00).
3. Character (char):- It is used to store a single letter, digit, punctuation mark, symbol,
or blank space. Example: a, b, 1,5,@,/,” etc
4. String (str or text):- It is a sequence of characters and the most commonly used data
type to store text. Additionally, a string can also include digits and symbols; however,
it is always treated as text. A phone number is usually stored as a string (+1-999-666-
3333) but can also be stored as an integer (9996663333).
5. Boolean (bool):- It represents the values true and false. When working with the
Boolean data type, it is helpful to keep in mind that sometimes a Boolean value is
also represented as 0 (for false) and 1 (for true).
6. Array:- Also known as a list, an array is a data type that stores a number of elements
in a specific order, typically all of the same type. Since an array stores multiple
elements or values, the structure of data stored by an array is referred to as an array
data structure.
7. Pointers: Pointers refer to a variable that holds the address of another variable; like
any other variable, they too have a data type.
33
User-defined Data Types in C
There are two user-defined data types struct and union, that can be defined by the user
with the help of the combination of other basic data types.
1. Struct Data Type: One of the unique features of C language is to store values of
different data types in one variable. The keywords struct and union are provided to derive
a user-defined data type. For example,
A union is a special case of struct where the size of union variable is not the sum of sizes
of individual elements, as in struct, but it corresponds to the largest size among individual
elements. Hence, only one of elements can be used at a time. Look at following example:
34
Source code is provided to a language translator which converts it into machine-
understandable code which is called machine code or object code. The computer can not
understand direct source code, a computer understands machine code and executes it. It is
considered a fundamental component of a computer. In simple we can say source code is
a set of instructions/commands and statements which is written by a programmer by
using a computer programming language like C, C++, Java, Python, Assembly language,
etc.
Object code is the output of a compiler after it processes the source code. The object
code is usually a machine code, also called a machine language, which can be
understood directly by a specific type of CPU (central processing unit).
Executable (also called the Binary) is the output of a linker after it processes the
object code. A machine code file can be immediately executable (i.e., runnable as a
program), or it might require linking with other object code files (e.g. libraries) to
produce a complete executable program.
35
OPERATORS
Operators are symbols that are used to perform operations on operands.
For Example:
var sum=10+20;
Here, + is the arithmetic operator and = is the assignment operator.
36
Operator Description Example
== Is equal to 10==20 = false
=== Identical (equal and of same type) 10==20 = false
!= Not equal to 10!=20 = true
!== Not Identical 20!==20 = false
> Greater than 20>10 = true
>= Greater than or equal to 20>=10 = true
< Less than 20<10 = false
<= Less than or equal to 20<=10 = false
3. Bitwise Operators:- The bitwise operators perform bitwise operations on operands.
The bitwise operators are as follows:
Operator Description Example
& Bitwise AND (10==20 & 20==33) = false
| Bitwise OR (10==20 | 20==33) = false
^ Bitwise XOR (10==20 ^ 20==33) = false
~ Bitwise NOT (~10) = -10
<< Bitwise Left Shift (10<<2) = 40
>> Bitwise Right Shift (10>>2) = 2
>>> Bitwise Right Shift with Zero (10>>>2) = 2
37