0% found this document useful (0 votes)
647 views36 pages

BCA I Year C Notes

C programming language was initially developed by Dennis Ritchie in 1972 as a system programming language to write operating systems. It features low-level access to memory and a simple set of keywords that make it suitable for system programming like operating systems. Many later languages have borrowed syntax and features from C.

Uploaded by

Sandy
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)
647 views36 pages

BCA I Year C Notes

C programming language was initially developed by Dennis Ritchie in 1972 as a system programming language to write operating systems. It features low-level access to memory and a simple set of keywords that make it suitable for system programming like operating systems. Many later languages have borrowed syntax and features from C.

Uploaded by

Sandy
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/ 36

S. S. JAIN SUBODH P.G.

(AUTONOMOUS) COLLEGE,
JAIPUR
BCA I Year Sec B
C Programming Language
UNIT-I
C Language Introduction

 C is a procedural programming language. It was initially developed


by Dennis Ritchie in the year 1972. 
 It was mainly developed as a system programming language to
write an operating system.
 The main features of C language include low-level access to
memory, a simple set of keywords, and clean style, these features
make C language suitable for system programmings like an
operating system or compiler development.

Many later languages have borrowed syntax/features directly or


indirectly from C language.
 Like syntax of Java, PHP, JavaScript, and many other languages are
mainly based on C language. C++ is nearly a superset of C language
(There are few programs that may compile in C, but not in C++).
Beginning with C programming:

Structure of a C program
After the above discussion, we can formally assess the
structure of a C program. By structure, it is meant that
any program can be written in this structure only.
Writing a C program in any other structure will hence
lead to a Compilation Error.
The structure of a C program is as follows:
Beginning with C programming:
Structure of a C program
After the above discussion, we can
formally assess the structure of a C
program. By structure, it is meant that any
program can be written in this structure
only. Writing a C program in any other
structure will hence lead to a Compilation
Error.The structure of a C program is as
follows:
• The components of the above structure are:
• Header Files Inclusion: The first and foremost
component is the inclusion of the Header files in a C
program.
A header file is a file with extension .h which
contains C function declarations and macro
definitions to be shared between several source files.
Some of C Header files:
• stdio.h – Defines core input and output functions
• string.h – Defines string handling functions
• math.h – Defines common mathematical
functions
Compile and Run C Program

• To compile and run a C language program,


you need a C compiler.
• To setup a C language compiler in your
Computer/laptop, there are two ways:
• Download a full fledged IDE like Turbo C or
• Microsoft Visual C++, which comes along with
a C language compiler.
• Or, you use any text editor to edit the program
files and download the C compiler separately.
 Step 1 : Open turbo C IDE(Integrated
Development Environment), click on File and
then click on New
Step 2 : Write the above example as it is
 compilation is the process where the compiler checks whether the program is correct syntax wise, and there are no errors in the syntax.
When we run a compiled program, then it actually executes the statements inside the main() function.

Step 3 : Click on compile or press Alt+f9 to compile the code


Step 4 : Click on Run or press Ctrl+f9 to run the code
Step 5 : Output
Pseudo code
 Pseudo code is a term which is often used in programming
and algorithm based fields.
 It is a methodology that allows the programmer to represent
the implementation of an algorithm. Simply, we can say that
it’s the cooked up representation of an algorithm.
 Often at times, algorithms are represented with the help of
pseudo codes as they can be interpreted by programmers no
matter what their programming background or knowledge
is.
 Pseudo code, as the name suggests, is a false code or a
representation of code which can be understood by even a
layman with some school level programming knowledge.
 C Language books
 Balaguruswamy
 Vikas Thada
 Venogopal
 Algorithm: It’s an organized logical sequence of
the actions or the approach towards a particular
problem. A programmer implements an algorithm
to solve a problem. Algorithms are expressed
using natural verbal but somewhat technical
annotations.

 Pseudo code: It’s simply an implementation of an


algorithm in the form of annotations and
informative text written in plain English. It has no
syntax like any of the programming language and
thus can’t be compiled or interpreted by the
computer.
Advantages of Pseudocode
1. Improves the readability of any approach. It’s one of
the best approaches to start implementation of an
algorithm.
2. Acts as a bridge between the program and the
algorithm or flowchart. Also works as a rough
documentation, so the program of one developer can
be understood easily when a pseudo code is written
out. In industries, the approach of documentation is
essential. And that’s where a pseudo-code proves vital.
3. The main goal of a pseudo code is to explain what
exactly each line of a program should do, hence
making the code construction phase easier for the
programmer.
Pseudo-code
1. Arrange the sequence of tasks and write the pseudocode accordingly.
2. Start with the statement of a pseudo code which establishes the main
goal or the aim.
 Example:
 This program will allow the user to check the number whether it's
even or odd.
3. The way the if-else, for, while loops are indented in a program, indent
the statements likewise, as it helps to comprehend the decision
control and execution mechanism. They also improve the readability
to a great extent.

 Example:
 if "1"
 print response
 "I am case 1"
 if "2"
 print response
 "I am case 2"
4. Use appropriate naming conventions. The human tendency
follows the approach to follow what we see. If a programmer
goes through a pseudo code, his approach will be the same
as per it, so the naming must be simple and distinct.
5. Use appropriate sentence casings, such as CamelCase for
methods, upper case for constants and lower case for
variables.
6. Elaborate everything which is going to happen in the actual
code. Don’t make the pseudo code abstract.
7. Use standard programming structures such as ‘if-then’, ‘for’,
‘while’, ‘cases’ the way we use it in programming.
8. Check whether all the sections of a pseudo code is complete,
finite and clear to understand and comprehend.
9. Don’t write the pseudo code in a complete programmatic
manner. It is necessary to be simple to understand even for a
SUBODH
layman or client,subodh
hence don’t incorporate too many technical
terms. even
EVEN
Flowchart
 Flowchart is a graphical representation of an algorithm.
Programmers often use it as a program-planning tool to solve
a problem. It makes use of symbols which are connected
among them to indicate the flow of information and
processing.
 The process of drawing a flowchart for an algorithm is
known as “flowcharting”.

 Basic Symbols used in Flowchart Designs

1. Terminal: The oval symbol indicates Start, Stop and Halt in a


program’s logic flow. A pause/halt is generally used in a
program logic under some error conditions. Terminal is the first
and last symbols in the flowchart.
 2. Input/Output: A parallelogram denotes any
function of input/output type. Program
instructions that take input from input devices
and display output on output devices are
indicated with parallelogram in a flowchart.

 3. Processing: A box represents arithmetic


instructions. All arithmetic processes such as
adding, subtracting, multiplication and division
are indicated by action or process symbol.
 4. Decision Diamond
symbol represents a
decision point.
Decision based
operations such as
yes/no question or
true/false are
indicated by diamond
in flowchart.
 5. Connectors: Whenever flowchart becomes
complex or it spreads over more than one page, it
is useful to use connectors to avoid any confusions.
It is represented by a circle.


6. Flow lines: Flow lines indicate the exact
sequence in which instructions are executed.
Arrows represent the direction of flow of control
and relationship among different symbols of
flowchart.
Algorithm
 An algorithm is used to provide a solution to a
particular problem in form of well-defined
steps. Whenever you use a computer to solve a
particular problem, the steps which lead to the
solution should be properly communicated to
the computer. While executing an algorithm on
a computer, several operations such as
additions and subtractions are combined to
perform more complex mathematical
operations. Algorithms can be expressed using
natural language, flowcharts, etc.
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.
 Algorithm is a step-by-step procedure, which
defines a set of instructions to be executed in a
certain order to get the desired output.
Algorithms are generally created independent
of underlying languages, i.e. an algorithm can
be implemented in more than one
programming language.
Characteristics of an Algorithm
An algorithm should have the following characteristics −

a. Unambiguous − Algorithm should be clear and unambiguous.


Each of its steps (or phases), and their inputs/outputs should
be clear and must lead to only one meaning.
b. Input − An algorithm should have 0 or more well-defined
inputs.
c. Output − An algorithm should have 1 or more well-defined
outputs, and should match the desired output.
d. Finiteness − Algorithms must terminate after a finite number
of steps.
e. Feasibility − Should be feasible with the available resources.
f. Independent − An algorithm should have step-by-step
directions, which should be independent of any programming
code.
Write an algorithm to add two numbers entered
by the user.
 Step 1: Start

 Step 2: Declare variables num1, num2 and sum.

 Step 3: Read values num1 and num2.

 Step 4: Add num1 and num2 and assign the

result to sum.
sum←num1+num2
 Step 5: Display sum

 Step 6: Stop
Write an algorithm to find the largest among three different
numbers entered by the user.

 Step 1: Start
 Step 2: Declare variables a,b and c.
 Step 3: Read variables a,b and c.
 Step 4: If a > b
 If a > c
 Display a is the largest number.
 Else
 Display c is the largest number.
 Else
 If b > c
 Display b is the largest number.
 Else
 Display c is the greatest number.
 Step 5: Stop
C Language Basic Syntax Rules
 C language syntax specify rules for sequence of
characters to be written in C language. In simple
language it states how to form statements in a C
language program - How should the line of code start,
how it should end, where to use double quotes, where
to use curly brackets etc.

 The rule specify how the character sequence will be


grouped together, to form tokens. A smallest
individual unit in C program is known as C Token.
Tokens are either keywords, identifiers, constants,
variables or any symbol which has some meaning in C
language. A C program can also be called as a
collection of various tokens.
 In the following program,

 #include
 int main()
 {
 printf("Hello,World");
 return 0;
 }
 if we take any one statement:

 printf("Hello,World");
 Then the tokens in this statement are→ printf, (,
"Hello,World", ) and ;.

 So C tokens are basically the building blocks of a C program.


 Comments
 Comments are plain simple text in a C program that
are not compiled by the compiler. We write
comments for better understanding of the program.
Though writing comments is not compulsory, but it
is recommended to make your program more
descriptive. It make the code more readable.

 There are two ways in which we can write


comments.

 Using // This is used to write a single line


comment.
 Using /* */: The statements enclosed within /* and
*/ , are used to write multi-line comments.
Keywords in C
 Keywords are preserved words that have special meaning in C
language. The meaning of C language keywords has already
been described to the C compiler. These meaning cannot be
changed. Thus, keywords cannot be used as variable names
because that would try to change the existing meaning of the
keyword, which is not allowed.(Don't worry if you do not
know what variables are, you will soon understand.) There are
total 32 keywords in C language.

 auto double intstruct


 break else long switch
 case enum register typedef
 const extern return union
 char float short unsigned
 continue for signed volatile
 default goto sizeof void
 do if static while
What are Identifiers?
In C language identifiers are the names given to variables,
constants, functions and user-define data. These identifier are
defined against a set of rules.

Rules for an Identifier


1) An Identifier can only have alphanumeric characters(a-z ,
A-Z , 0-9) and underscore(_).
2) The first character of an identifier can only contain
alphabet(a-z , A-Z) or underscore (_).
3) Identifiers are also case sensitive in C. For example name
and Name are two different identifiers in C.
4) Keywords are not allowed to be used as Identifiers.

5) No special characters, such as semicolon, period,


whitespaces, slash or comma are permitted to be used in
or as Identifier.
 When we declare a variable or any function in C language
program, to use it we must provide a name to it, which
identified it throughout the program, for example:

 int myvariable = 34
 Here myvariable is the name or identifier for the variable
which stores the value "Studytonight" in it.

Character set
 In C language characters are grouped into the following

catagories,

 Letters(all alphabets a to z & A to Z).


 Digits (all digits 0 to 9).
 Special characters, ( such as colon :, semicolon ;, period .,
underscore _, ampersand & etc).
 White spaces.

You might also like