Introduction To C Language
Introduction To C Language
Submitted by:
Manika Yonzan
“M21”
Submitted to : Sandeep Shrestha sir
Some Fact about C programming logic
• It was developed at AT&T’s Bell Laboratories of the USA in the 1970s.
• It was designed and developed by Dennis M. Ritchie.
• It stands between high level language and low level language. So it is often known as middle level language.
• It is simple, reliable and easy to use.
• It is more efficient then unstructured code because of the minimized branching code.
• The program code is secured.
• It is designed to have both; relatively good programming efficiency and relatively good machine efficiency.
• As the program extends, it is very difficult to fix the bugs.
• C doesn’t have effective if the sub-routines called frequently there by killing the time.
• It uses compiler as language translator.
• It translates whole program at a time.
• It is easy to learn.
Program Design Tools
• Program design tool used to design a program before it is actually
developed.
Types of program design tool are:
Algorithm
Flowchart
Pseudo code
Algorithm
• An algorithm is the finite set of step by step set of statements that solve a
particular problem.
• For example:
Step 1: START
Step 2: Read two numbers A and B
Step 3: Add the number A and B And store in D. or D=A+B
Step 4: Display D or Print D.
Step 5: Stop
Flowchart
• A flowchart is diagrammatic representation that illustrates the sequence of
operations to be performed.
Advantages:
Easier to explain the logic of a program through the flowchart.
Effective analysis of the program.
Symbol Function Meaning
Start/Stop point It indicates starting point and ending point in a program.
void main( )
{
int a, b, c ;
float x, y, z;
char ch;
}
Constant VS Variable
Constant Variable
• A value cannot be altered by the • A storage location paired with an
program during normal execution . associated symbolic name which contains
a value.
• Similar to variable , but it cannot be
modified by the program once it is • A container or a storage area to store value.
defined . •
Can be changed by the program once it is
• Cannot be changed by the program defined.
once it is define.
Operators and Expression
● An operator is a symbol the instructs C to perform some operation or action.
● C has a wide range of operators to perform various operations.
● C offer different type of operators :
○ Arithmetic operator
○ Equality operator
○ Assignment Operator
○ Relational operators
○ Logical operator
○ increment /decrement operator
○ Bitwise operator
Arithmetic operator
● An arithmetic operator performs mathematical operations such as
addition, subtraction, multiplication, division etc on numerical
values (constants and variables).
Operators Purpose Example
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Reminder a%b
Relational operator
● The relational operators are used to check the relationship
between two operands.
● It checks whether two operands are less than or greater than, less
than equal greater than equal to etc.
Operator Purpose Example
< Less than a<b
<= Less than or equals to a<=b
> Greater than a>b
>= Greater than or equals to a>=b
Logical operator
➢ C programming has two operators increment ++ and decrement -- to change the value of an operand by 1. Increment ++
❖ Assignment Operators
➢ An assignment operator is used for assigning a value to a variable. The most common assignment operator is =
❖ Bitwise operator
During computation, mathematical operations like: addition, subtraction, multiplication, division, etc are converted to bit-level
which makes processing faster and saves power.
Control Structure
• As the name suggest the "Control Structure" enables us to specify the order in which the various
instruction in a program are to be executed by the computer. In other word the control structure
determine the "Flow of control" in a program they are :
• Sequence
• Decision
• Looping
• Jump
• Label
Sequence
• he line-by-line execution by which statements are executed sequentially, in the same
Flowchart
order in which they appear in the program.
• Syntax: Statement_1
statement_1;
Statement_2
statement_2;
| Statement_n
statement n;
Decision Flowchart
Expression is true
f (expression)
Next statement
statement ;
Jump Statements
• The type of Control Statements in C/C++ used to
interrupt the normal flow of the program.
• It makes the program jump to another section of
the program unconditionally when encountered.
• It can also be used to terminate any loop.
• It' type are
1. Break statement
2. Continue statement
3. Goto statement
• The control statements used in the C Label
language help a user to specify a
program control's flow is called label.
• Labels just indicate locations in the
code and reaching a label has no effect
on the actual execution.
• Syntax
goto label;
..
.
label: statement;
Looping
• Loop control statements in C are used to perform looping
operations until the given condition is true
• Control comes out of the loop statements once
condition becomes false.
• Syntax
or(initialization; condition; increment/decrement)
{
statement (s)
}
For Loop
• A for loop is a repetition control structure that allows
you to efficiently write a loop that needs to execute a
specific number of times.
• Syntax:
For ( initialization; condition; Increment/decrement)
{
Statement (s);
}
While Loop
initialization;
while(condition)
{
statement_1;
----------------
statement_2;
increment/decrement
}
Do While Loop
• A do while loop is a control flow statement that executes a block of code at least
once, and then either repeatedly executes the block, or stops executing it, depending on a
given Boolean condition at the end of the block.
• Syntax:
initialization ;
do
{
statement1;
---------------
statement n;
increment/decrement ;
}
while (condition)
!! THE END!!