C TheorytillUNIT2smpart PDF
C TheorytillUNIT2smpart PDF
The two main categories of software are application software and system
software. An application is software that fulfills a specific need or performs
tasks. System software is designed to run a computer's hardware and
provides a platform for applications to run on top of.
• Antivirus software: Protects your system from viruses, malware, and other online
threats
• Disk cleanup tools: Removes temporary data and unnecessary files to free up disk
space
• System optimizers: Improves startup times, manages resources, and optimizes settings
to enhance system performance
Low-level languages are used to write the While high-level languages are used
system software. to write the application software.
• Algorithm
A set of rules or step-by-step instructions that define how a program is executed.
• Flowchart
A diagram that visually represents an algorithm, using boxes and arrows to show the
steps in a process.
Algorithm :
• Machine language
Also known as binary language, machine language is made up of binary and
hexadecimal characters.
• Assembly language
A low-level language that's designed to communicate with a computer's
hardware. Assembly language is similar to machine code, but uses words instead of
numbers.
• High-level language
A programming language that's easier for humans to understand and write. High-level
languages are closer to natural language and are less dependent on the computer's
hardware.
• C++
An intermediate-level language that includes both high and low-level language
features. C++ is portable, meaning programs written in C++ can run on different
operating systems.
• Python
A high-level language that's often used for data science, artificial intelligence, and
machine learning. Python is also used for scripting and web development.
• Fortran
A high-level language that's mainly used by the scientific community. Fortran is fast
and portable, and handles arrays and parallelism well.
• Java
A high-level language that's human-readable and has a simple syntax.
MACHINE LANGUAGE ASSEMBLY LANGUAGE
Machine language statements are not Assembly language statements are human-
human-readable or understandable. understandable language statements.
1. Compiler
The language processor that reads the complete source program written in
high-level language as a whole in one go and translates it into an equivalent
program in machine language is called a Compiler. Example: C, C++, C#.
In a compiler, the source code is translated to object code successfully if it is
free of errors. The compiler specifies the errors at the end of the compilation
with line numbers when there are any errors in the source code. The errors
must be removed before the compiler can successfully recompile the source
code again the object program can be executed number of times without
translating it again.
2. Assembler
The Assembler is used to translate the program written in Assembly
language into machine code. The source program is an input of an
assembler that contains assembly language instructions. The output
generated by the assembler is the object code or machine code
understandable by the computer. Assembler is basically the 1st interface that
is able to communicate humans with the machine. We need an assembler to
fill the gap between human and machine so that they can communicate with
each other. code written in assembly language is some sort of
mnemonics(instructions) like ADD, MUL, MUX, SUB, DIV, MOV and so on.
and the assembler is basically able to convert these mnemonics in binary
code. Here, these mnemonics also depend upon the architecture of the
machine.
For example, the architecture of intel 8085 and intel 8086 are different.
3. Interpreter
The translation of a single statement of the source program into machine
code is done by a language processor and executes immediately before
moving on to the next line is called an interpreter. If there is an error in the
statement, the interpreter terminates its translating process at that statement
and displays an error message. The interpreter moves on to the next line for
execution only after the removal of the error. An Interpreter directly executes
instructions written in a programming or scripting language without
previously converting them to an object code or machine code. An interpreter
translates one line at a time and then executes it.
Example: Perl, Python and Matlab.
Loader
The loader is a specialized operating system module that comes last in the
picture. It loads the final executable code into memory.
Afterward, it creates the program and data stack. Then, it initializes
various registers and finally gives control to the CPU so that it can start
executing the code.
Unit II
tructure of C program
In this section you will learn Structure of C program. How is C program look like? There
are total 5 section of C program. You will learn basic skeleton of C program or you can
say basic things of C program.
Total 5 section are there:
1. Comment.
2. Pre-processor Directives.
3. Declaration.
4. Main Function.
5. User Define Function.
Comment in C
C program contain group of statement. All statement execute in program but some of
the statement not execute. That are called comment statement. Comment are the C
program statement which will not execute. We can also say it None-Executable
statement.
Now see the program code. By comment we are giving the information about the
program logic. Like we are printing the value of variable " a ".
Example of comment:
void main()
int a=10;
clrscr();
getch();
Output:
Value of A is: 10
Now in this program code we are making multiline comment by giving more information.
void main()
int a=10;
clrscr();
program of C.*/
getch();
Output:
Value of A is: 10
Pre-processor Directives
hash (#) symbol is called pre-processor and include called directives. Both together
called pre-processor directives.
#include
Declaration
In C we have two type's declaration. Declaring a variable or a function called
declaration.
1. Local Declaration
2. Global Declaration
Local Declaration
Declaring a variable inside the function or within the block called local declaration,
whose scope is within the function.
fun()
int a = 10;
printf(" %d ",a);
fun1()
In above example fun1() cannot access the variable "a" because the scope of variable
is within the block or within the function.
Global Declaration
Declaring a variable outside the function called global declaration, whose scope is
outside the function and inside the function.
int a = 10;
fun()
fun1()
In above example variable "a" declared as a global variable and both function can
access the global variable.
main function
Every program will have main function. main function is the entry point of the program
execution. When we execute the program, compiler first execute the main function.
This happens when you declare a global or static variable, which defines a fixed-size
block of memory. The memory is allocated during compile time and the size and location
of the memory cannot be changed.
• Character set
The C programming language supports four types of characters: alphabets, digits,
special characters, and white space.
• Keywords
These are reserved words with predefined meanings that are used to write programs
in C. They cannot be used as variable names or identifiers.
• Data types
C has several built-in data types, including:
• Char: Represents the character data type and stores a variable with a single character. It
has two subtypes: signed char and unsigned char.
• Float: Stores decimal values in variables. It has a storage size of 4 bytes and can store up
to 6 digits after the decimal point.
• Union: A special data type that stores multiple types of data in the same memory location.
• Struct: A user-defined data type that stores variables of different data types.
Type of operator:
In C programming language, unary, binary &ternary operators are useful for carrying out
mathematical operations.
1. Unary operators are those that work on single operand e.g. increment operator(
++) or the decrement operator( - - ). int a =b++; or something like int C =d- -;
2. Binary operators are the one that operate on two operands e.g. ‘+’, ‘ -’, ‘ *’, ‘/’.
Syntax can be like int C=a+b;
3. Ternary operators are the one that operates on three operands. It takes three
argumets . 1st argument is checked for its validity . If it is true 2nd argument is
returned else third argument is returned. For example if we write int C= a>b ? e:f;
now if a is greater than b 'e' is returned otherwise 'f' is returned
1. The & (bitwise AND) in C takes two numbers as operands and does AND
on every bit of two numbers. The result of AND is 1 only if both bits are
1.
2. The | (bitwise OR) in C takes two numbers as operands and does OR on
every bit of two numbers. The result of OR is 1 if any of the two bits is 1.
3. The ^ (bitwise XOR) in C takes two numbers as operands and does XOR
on every bit of two numbers. The result of XOR is 1 if the two bits are
different.
4. The << (left shift) in C takes two numbers, the left shifts the bits of the
first operand, and the second operand decides the number of places to
shift.
5. The >> (right shift) in C takes two numbers, right shifts the bits of the first
operand, and the second operand decides the number of places to shift.
6. The ~ (bitwise NOT) in C takes one number and inverts all bits of it.
Let’s look at the truth table of the bitwise operators.
X& X| X^
X Y Y Y Y
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
https://www.youtube.com/watch?v=cy2JF6iFv8k
Right Shift:
10>>3(no. of steps)divided by 2
https://www.youtube.com/watch?v=27p2Dcc-B5o
https://www.log2base2.com/C/bitwise/bitwise-left-shift-operator-in-c.html