0% found this document useful (0 votes)
52 views50 pages

Unit 1 BCA Clang

Uploaded by

panthers82638
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views50 pages

Unit 1 BCA Clang

Uploaded by

panthers82638
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

C-Programming

Lec - 1
Unit - 1
Introduction to Programming Language
Fundamentals
Topics Covered:
• Basic Introduction of Programming Language
• Types of Programming Language
• Algorithms
• FlowCharts
Basic Introduction of Programming
Language
• A programming Language is a formal computer language or
constructed language designed to communicate instructions to
machine, mainly computer.
• Programming language can be used to create programs to control the
behaviour of machine to express algorithm.
• C is a high level and general purpose programming language that is
ideal for portable applications.
• C is a procedural programming language.
Types of Programming Language
• There are mainly 3 kinds of
programming language:
• Machine Language(Low Level)
• Assembly Language(Middle Level)
• High-level Language(High Level)
Machine Language(Low Language)
• Low-level programming languages are languages that provide little to
no abstraction between the language itself and the processor's
instructions. In other words, these low-level languages closely
resemble the machine code and are hence referred to as 'close to
hardware'. The advantage here is that the processors can run low-level
programs directly, without the need for an interpreter or compiler. This
is why programs written in low-level programming languages are
extremely fast to run.

• Examples of low-level programming languages are- Binary code,


Machine language, and Assembly language.
Assembly Language(Middle Level)
• As the name suggests, a mid-level language refers to all the languages
that lie between high and low-level programming languages. An MLL
acts as a bridge between raw hardware and programs by interacting
with the abstraction layer. This is why they are often referred to as
pseudo or intermediate-level programming languages.

• Examples of mid-level languages are- C, Java, and C++.


High-level Language(High Level)
• The high-level programming languages allow for the greatest amount of
abstraction between machine code and the language itself. So much so,
that they appear close to human languages rather than machine
languages. For computers to then understand and execute the
commands we use compilers that first convert the HLL into computer
languages. The primary benefit of high-level programming languages is
that it's simple to learn and write in, as well as maintain.

• Examples of high-level programming languages are Python, Java,


JavaScript, Pascal, PHP, Swift, etc.
Algorithms
• An algorithm is a set of commands that must be followed for a
computer to perform calculations or other problem-solving
operations.
• According to its formal definition, an algorithm is a finite set of
instructions carried out in a specific order to perform a particular task.
• Algorithm is the first step to solution process, after analysis of the
problem, programmers write the algorithm of problem.
Qualities of a Good Algorithm
• Input and output should be defined precisely.
• Each step in the algorithm should be clear and unambiguous.
• Algorithms should be most effective among many different ways to
solve a problem.
• An algorithm shouldn't include computer code. Instead, the algorithm
should be written in such a way that it can be used in different
programming languages.
Examples
Advantages of algorithm:
• It is a step-wise representation of a solution to a given problem, which makes it
easy to understand.
• An algorithm uses a definite procedure.
• It is not dependent on any programming language, so it is easy to understand for
anyone even without programming knowledge.
• Every step in an algorithm has its own logical sequence so it is easy to debug.
• By using algorithm, the problem is broken down into smaller pieces or steps
hence, it is easier for programmer to convert it into an actual program

Disadvantages of algorithm:
• Writing algorithm takes a long time.
• An Algorithm is not a computer program, it is rather a concept of how a program
should be.
To-Do List
• Write an algorithm to find out if the number is odd or even.
• Write algorithm to find the cube of a number.
FlowCharts
• A flowchart is a diagram
that depicts a process,
system or computer
algorithm.
Example of FlowChart
To-Do List
• Draw a flowchart to add two number entered by the user.
• Draw flowchart to find the largest among three different number
entered by the user.
To-Do Questions
• Write an algorithm and then draw a flowchart for finding average of
10 numbers.
• Write the Difference between Algorithm and Flowchart.
C-Programming
Lec - 2
Unit - 1
Introduction to Programming Language
Fundamentals
Topics Covered:
• Introduction to C
• History
• Structure of C programming
• Translator and Assembler
• Compiler
• Interpreter
History of C language
• C programming language was
developed in 1972 by Dennis Ritchie
at bell laboratories of AT&T (American
Telephone & Telegraph), located in
the U.S.A.

• Dennis Ritchie is known as the


founder of the c language.

• It was developed to overcome the


problems of previous languages such
as B, BCPL, etc.
Structure of C programming
• C programming language is known as POP programming language.
POP = Procedure Oriented Programming.
• Every C program must have a main function.
• User can write a c program between opening and closing bracket.
• C programming language is a case sensitive programming language.
• Every statement in C program ends with semicolon(;)
Example
Translator and Assembler
• A translator is a computer program that performs the translation of a
program written in a programming language into a functionally
equivelent program in the computer language, without losing the
functional or logical structure of the original code.

• The translation of an assembly language program into a machine


language program is done by another program known as Assembler
Compiler
• A compiler is a software that converts the source code to the object
code.
• In other words, we can say that it converts the high-level language to
machine/binary language.
• Moreover, it is necessary to perform this step to make the program
executable. This is because the computer understands only binary
language.
Interpreter
• Interpreter takes single instruction as input
• No intermediate object code is generated Conditional control
statements are executes slower
• Memory requirement is less.
• Image
To-Do List
• Difference between Compiler and Interpreter
C-Programming
Lec - 3
Unit - 1
Introduction to Programming Language
Fundamentals
Topics Covered:
• Character Sets
• Keyword and Identifiers
• Formatted Input and Output Statements
• Variable and constants
• Data Types
• Evaluation of Expression and Type Casting
Character Sets
• The characters that can be used to form words, number and
expression depend upon the computer on which the program is
running.
• They are of 4 categories
• Letter [A-Z or a-z]
• White spaces
• Special Symbols [, ; ? / \ % &]
• Special Charaters [New line, Horizontal tab, Carriage return]
Keywords
• All the keyword have fixed meaning and these meaning cannot be
changed.
• These serve as basic building blocks for program statements.
Identifiers
• Identifiers refer to the names of variables, functions and arrays.
• These are user defined names and consists of sequence of letter and
digits.
• Both uppercase and lowercase are permitted, although lowercase
letters are commonly used.
Formatted Input and Output
Statements
Extras:
Data Types
• Variable is used to store any kind of data value and that value may be
change during the execution or run the program.
• Following syntax is used to declare the variable:
• Syntax: datatype variablename
• Example: int a;
• Example: float temp;
• Example: char name;
Data types continue
• During the declaration of variables, C program requires to specify the
type of data that needs to be stored.
• Data types can be classified into following types:
• Primary Data types
• User Defined Data types.
Primary Data type
• The following data types are primary data types that are used:
• Integer { numbers }
• Floating point { numbers and decimals }
• Character { alphabets }
• Double { same as float but more memory }
• Void { null }
Rules to declare variable name
• Name of variable must start with an alphbet.
• It should not be more than 31 character long.
• White space is not allowed in the variable name.
• It does not allow special characters.
• Only special character allowed is underscore(_).
• Keywords are not allowed in the variable name.
• Variable name must be declared before use.
Constants
• A constant refers to a value that cannot be changed during program
execution.
• C allows to declare constants same as variable declaration and its
value cannot be changed in the program.
• Use the “const” Keyword to declare a constant as shown below:
• int const x = 20;
• const int x = 20;
To-Do List
• Difference between variables and constants.
• There are 2 types of constants: (Learn about them)
• Numeric constant
• Character constant
C-Programming
Lec - 4
Unit - 1
Introduction to Programming Language
Fundamentals
Topics Covered:
• Operators in C
• Type casting
Operators in C
• Operators are the fundamental of any programming language.
• We can define operators as symbols that can help us to perform
specific mathametical and logical computations on operands.
• There are following types of Operators
• Arithmatic Operator
• Assignments Opertator
• Relational Operator
• Logical Operator
• Increment/Decrement Operator
• Ternary Operator
Assignment Operators
Operator Description Example
+ Add the Operands A + B = 30
- Subtracts seconds operand from the first A - B = 10
* Multiplies the operands A * B = 200
/ Divides the numberator with denominator B/A=2
% Gives the remainder of the division B%A=0

Take A = 10 and B = 20
Relational Operator
Operator Description Example
== Checks if the values of 2 operands are equal or not A == B is not true
!= Checks if the values of 2 operands are not equal or not A != B is true
> Checks if the value of left side is greater than the right side A > B is not true
< Checks if the value of left side is less than the right side A < B is true
>= Checks if the value of left side is greater than or equal to the A >= B is not true
right side
<= Checks if the value of left side is less than or equal to the A <= B is true
right side
Assignment Operator
Operator Description Example
= assign the value to variable x = 30
Logical Operator
Operator Description Example
&& AND operator. If both the operands are 1 then condition is A && B is false
true
|| OR operator. If any one operands are 1 then condition A || B is true
becomes true
! NOT operator. Used to reverse the logic of any operation !(A && B) is true

Assume A = 1
and B = 0
Increment and Decrement Operator
• Suppose, A = 10

• Increment Operator
• A++ , ++A = 11
• Decrement Operatior
• A-- , --A = 9
Ternary Operator
• It takes 3 arguements to perform
operation
Type Casting
• Type casting is used to convert from one type to another
• There are 2 type of Conversion
• Implicit Type conversion
• Explicit Type conversion
Implicite Type Casting
• Automatic Type casting.
• Done by the compiler on its own.
• No loss of data

• Bool->char->short->int->long->double
Explicit Casting

You might also like