Introduction To C Language

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 30

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.

  Input/Output It indicates when an input or output operation to be


performed.

  Processing operation It indicates the movement of data, the editing of data or


calculation.

  Decision making It indicates a point of the branch. It is used to check


logical condition. It has one entry and two exit
points which are true and false.

  Connector It indicates a logic from one page of the flowchart to


another.
Pseudo code
• Pseudo code is a tool to formulate the processing step of a program.
• It uses English phase and mathematical statement to describe the processing step of a program or module.
• Example:
get price of item
get sales tax rate
sales tax = price of item times sales tax rate
final price= price of item plus sales tax
display final price
halt
C tokens
• The basic and smallest element used to develop the program and
recognized by the c compiler is called as C tokens.
• C token includes:
 Identifier
 Keyword
 Constant and variable
 Operator
Identifier

• The identifier is the name given to various program elements such as


variable, function, label, and an other user defined item.
• It can be a combination of numbers, alphabets and special symbol.
• The first character of an identifier must be an alphabet or underscore.
• In an identifier, uppercase and lowercase alphabets are treated as
differently.
• There are 53 alphabetic characters: 52 are letters and one is underscore.
Keyword
• The keyword is the reserved word that has standard and predefined
meaning in c.
• We cannot use a keyword for any other purpose other than as a predefined
task in a c program.
• There are 32 keywords.
• All the data types are keywords but all keywords are not data type.
All 32 keywords:

auto const double float int short struct Unsigned

Break continue Else for long Register switch void

Case Default Enum Goto Register sizeof typedef Volatile

char Do extern If return static union while


Constant
• A constant is a quantity that does not change during program execution.
• This quantity can be stored at a location in the memory
of the computer.
• Constant refers to fixed values that may not be altered
by the program.
• For example , Radius =3.14 is a constant.
• C has four types of constants. They are :
• Integer constant   
• Floating constant The
• Character constant 
• String constant
Variable
• Variable are most fundamental part of any programming language. Variable is a symbolic name , which is
used to store different type of data in the computer’s memory and may change during the program
execution. When user give the value to the variable, that value is stored at the same location occupied by
the variable. The variable may be of the integers , character, string, or floating type .
• Variable Declaration and Initialization:

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

• Logical operator is a symbol that logically connect the logical expression


i.e. it is used to connect two or more expression
Operators Purpose Example What it evacuates
&& AND A && b TRUE(1) only if both a and b are true:
otherwise it is false(0)

|| OR A || B True (1) if either a or b is true : false (0) only


if both are false

!= NOT !A False (0) if a is true : true(1) if a is false


Equality operator
● Equality operator is a symbol used to compare two operands . If they are
equal or not
● It executes either true or false result

Operators Purpose Example


== Equals to a==b
!= Not equals to a!=b
Other operators
❖ Increment and Decrement Operators

➢ C programming has two operators increment ++ and decrement -- to change the value of an operand by 1. Increment ++

increases the value by 1 whereas decrement -- decreases the value by 1.

❖ 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

• A statement or set of statements that is executed when a


particular conditions True and ignored when the condition is
False is called Decision Control Structure.
• The decision to execute a particular section is based on
Statement or block of
• checking a condition. statements
• Syntax

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

• A "While" Loop is used to repeat a specific


block of code an unknown number of times,
until a condition is met.
• Syntax:

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!!

You might also like