Introduction To Programing
Introduction To Programing
Introduction:
A programming language is a set of instructions and syntax used to
create software programs. Some of the key features of programming
languages include:
Syntax: The specific rules and structure used to write code in a
programming language.
Data Types: The type of values that can be stored in a program, such as
numbers, strings, and booleans.
Variables: Named memory locations that can store values.
Operators: Symbols used to perform operations on values, such as
addition, subtraction, and comparison.
• Control Structures: Statements used to control the flow of a program,
such as if-else statements, loops, and function calls.
• Libraries and Frameworks: Collections of pre-written code that can be
used to perform common tasks and speed up development.
• Paradigms: The programming style or philosophy used in the
language, such as procedural, object-oriented, or functional.
Compiler and Linker: Roles and Functions
• Compiler:
• Function:
• A compiler is a software tool that translates the high-level source
code written in a programming language (like C, C++, Java) into
machine code (binary code) that can be understood and executed by
a computer's processor.
• Stages: The process typically involves several stages: lexical analysis,
syntax analysis, semantic analysis, optimization, and code generation.
• Output:
• The output of a compiler is usually an executable file or an
intermediate representation (like bytecode in Java) that can be
further processed or executed.
2. Linker:
Function:
• After the compilation process, the linker takes over. Its primary function
is to combine multiple object files and libraries to produce a single
executable file or a library that can be loaded into memory for execution.
• Tasks:
• Symbol Resolution:
• The linker resolves references between different object files, ensuring
that functions and variables defined in one file and used in another are
correctly linked.
• Address Binding: It assigns final memory addresses to functions and
variables in the executable.
• Static and Dynamic Linking:
• Linking can be static (linker combines all necessary code into a single
executable file) or dynamic (linker links the program to external
libraries at runtime)
Introduction to Algorithms
• What Exactly Is an Algorithm?
• An algorithm is a set of steps for solving a known problem.
Steps of Algorithm
• Most algorithms are implemented to run following the four steps below:
• take an input
• access that input and make sure it's correct
• show the result
• terminate (the stage where the algorithm stop running)
Some steps of the algorithm may run repeatedly, but in the end, termination is what ends an
algorithm.
Example
• For a theoretical basis, for instance, an algorithm for dividing two
numbers and showing the remainder could run through the steps
below:
• Step 1: the user enters the first and second numbers – the dividend
and the divisor
• Step 2: the algorithm written to perform the division takes in the
number, then puts a division sign between the dividend and the
divisor. It also checks for a remainder.
• Step 3: the result of the division and remainder is shown to the user
• Step 4: the algorithm terminates
Characteristics of an algorithm:
Variables
• In a programming language, a variable is a memory location where
you store a value. The value that you have stored may change in the
future according to the specifications.
Example
• int x;
• Int X=5;
Data Types
• In C++, data types are declarations for variables. This determines the
type and size of data associated with variables.
For example,
int x = 13;
Here, x is a variable of type int. Meaning, the variable can only store
integers of either 2 or 4 bytes.
Rules for declaring variables and data
types
• There are set of rules to be followed while declaring variables and data
types in C Programming:
• The 1st letter should be alphabet.
• Variables can be combination of alphabets and digits.
• Underscore (_) is the only special character allowed.
• Variables can be written in both Uppercase and Lowercase or combination
of both.
• No Spaces allowed between Characters.
• Variable name should not make use to the C Reserved Keywords.
• Variable name should not start with a number
C++ Fundamental Data Types
The table below shows the fundamental data types, their meaning, and their sizes (in bytes):
Now, let us discuss these fundamental data types in more detail.
int Integer 2 or 4
float Floating-point 4
char Character 1
bool Boolean 1
String String 4
1. C++ int
•The int keyword is used to indicate integers.
•Its size is usually 4 bytes. Meaning, it can store values from -2147483648 to 2147483647.
•For example
Int salary;
3. C++ char
•Keyword char is used for characters.
•Its size is 1 byte.
•Characters in C++ are enclosed inside single quotes ' '.
•For example,
char test = 'h';
5. C++ bool
•The bool data type has one of two possible
values: true or false.
•Booleans are used in conditional statements and loops.
•For example,
bool cond = false;
• string: we use this for any data that is text. For example, a name or
address or message. In most programming languages, strings require
quotes. Notice that the text inside of the quotes can include spaces
and other special characters.