Unit - 2 PPS
Unit - 2 PPS
Jigar Dalvadi
UNIT-2 - Fundamentals of C
Features of C language
Simple and Efficient
The basic syntax style of implementing C language is very simple and easy to learn.
Fast
C is a statically typed programming language. Unlike Java and Python, which are
interpreter-based, C is a compiler-based program. This makes the compilation and
execution of codes faster.
Portability
Function-Rich Libraries
C comes with an extensive set of libraries with several built-in functions that make the
life of a programmer easy. Even a beginner can easily code using these built-in functions.
One of the most significant features of C language is its support for dynamic memory
management (DMA). It means that you can utilize and manage the size of the data
structure in C during runtime.
Pointers
With the use of pointers in C, you can directly interact with memory. As the name
suggests, pointers point to a specific location in the memory and interact directly with it.
Middle-Level Language
1|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
Structure of C Program
Documentation Section
The documentation section is the part of the program where the programmer gives the
details associated with the program. He usually gives the name of the program
Link Section
This part of the code is used to declare all the header files that will be used in the
program.
This leads to the compiler being told to link the header files to the system libraries.
Example
#include<stdio.h>
Definition Section
In this section, we define different constants. The keyword define is used in this part.
#define PI=3.14
This part of the code is the part where the global variables are declared. All the global
variable used are declared in this part.
The user-defined functions are also declared in this part of the code.
Every C-programs needs to have the main function. Each main function contains 2 parts.
2|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
A declaration part and an Execution part. The declaration part is the part where all the
variables are declared.
The execution part begins with the curly brackets and ends with the curly close bracket.
Both the declaration and execution part are inside the curly braces.
All the user-defined functions are defined in this section of the program.
Comments
In programming, comments are hints that a programmer can add to make their code
easier to read and understand.
Types of Comments
1. Single-line Comments in C
In C, a single line comment starts with //. It starts and ends in the same line. For example,
#include <stdio.h>
void main()
{
// create integer variable
int age = 25;
getch();
}
2. Multi-line Comments in C
3|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
Header files
In C language, header files contain the set of predefined standard library functions.
The ―#include‖ preprocessing directive is used to include the header files with ―.h‖
extension in the program.
4|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
Low-level languages are referred to as 'low' because they are very close to how different
hardware elements of a computer actually communicate with each other.
Low-level languages are machine oriented and require extensive knowledge of computer
hardware and its configuration.
There are two categories of low-level languages: machine language and assembly
language.
Machine language
Machine language, or machine code, is the only language that is directly understood by
the computer, and it does not need to be translated.
Assembly language
High-Level Languages
5|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
Advantages of flowchart
Proper debugging
Effective analysis
Efficient coding
Proper documentation
Efficient program maintenance
Disadvantages of flowchart
Time-consuming
Complex
Difficult to modify
It has no standard
Definition of Algorithm
Writing a logical step-by-step method to solve the problem is called the algorithm
In other words, an algorithm is a procedure for solving problems. In order to solve a
mathematical or computer problem, this is the first step in the process.
An algorithm includes calculations, reasoning, and data processing. Algorithms can be
presented by natural languages, pseudo code, and flowcharts, etc.
Advantages of algorithm
6|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
Disadvantages of algorithm
Step 1. BEGIN
Step 2. PRINT "Hello World"
Step 3. END
7|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
Step 1: Start
Step 2: Read values for Number1, Number2.
Step 3: Add Number1, Number2 and assign the result to a variable Sum.
Step 4: Display Sum
Step 5: Stop
Step 1: Start
Step 2: Read a number to Number
Step 3: Perform the Number modulo by 2
Step 4: If it is equal to 0 then go to Step 6 else go to step 5
Step 5: Print ―Number is odd‖ go to step 7
Step 6: Print ―Number is even‖
Step 7: Stop
Draw a flow chart and write an algorithm to find out whether a given number is zero or
positive or negative.
Algorithm:
Step 1. Start
Step 2. Print‖Enter a number‖.
Step 3. Read n.
Step 4. If n>0 then print ―The number is positive‖
8|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
Step 1: Start
Step 2: Read a, b .
Step 3: If a>b then Display ―a is the largest number‖ and goto step 5. Otherwise goto step 4
Step 4: Display ―b is the largest number‖..
Step 5: Stop.
9|Page
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
Step 1. Start
Step 2. Input A,B,C
Step 3. If (A>B) then goto step 4 otherwise goto step 5.
Step 4. If (A>C) then Print A otherwise goto step 7 .
Step 5: If (B>C) then Print B otherwise goto step 7.
Step 6: Print C
Step 7. Stop
10 | P a g e
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
In C programming, data types are declarations for variables. This determines the type and
size of data associated with variables.
The C programming language has five primitive or primary data types.
1. Integer (int): Refers to positive and negative whole numbers (without decimal), such
as 10, 12, 65, 3400, etc.
2. Character (char): Refers to all the ASCII character sets within single quotes such as
‗a‘, ‗A‘, etc.
3. Floating-point (float): Refers to all the real number values or decimal points, such as
3.14, 10.09, 5.34, etc.
4. Double (double): Used when the range exceeds the numeric values that do not come
under either floating-point or integer data type.
11 | P a g e
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
5. void
void is an incomplete type. It means "nothing" or "no type". You can think of void as
absent. For example, if a function is not returning anything, its return type should be
void.
12 | P a g e
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
1. Arithmetic Operators in C
2. Increment Operator in C
Mainly used for incrementing the value of an integer. It is represented by the ‗++‘
operator. ++x will increase the value of the variable x instantly. But if it is placed after
the variable then it gets increased before the execution of the next statement.
3. Decrement Operator in C
Mainly used for decrementing the value of an integer. It is represented by the ‗--‘
operator. --x will decrease the value of the variable x instantly. But if it is placed after the
variable then it gets decreased before the execution of the next statement.
4. Assignment Operators in C
The purpose of this operator is to assign value to a variable. The most used assignment
operator is ―=‖.
Operator Example
= a=b or b=a
+= a += b or a = a+b
-= a -=b or a = a-b
*= a *= b or a = a*b
/= a /= b or a = a/b
%= a %= b or a = a%b
13 | P a g e
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
5. Relational Operators in C
Mainly used for checking relationships between operands. With the help of this operator,
you can check whether one operand is equal to or greater than the other operand or not.
6. Logical Operators in C
In the C programming language, Logical operators are mostly used for decision
making. A logical operator returns either 0 or 1 whether the condition is true or false.
7. Conditional Operator in C
8. Bitwise Operator in C
C also provides special operators for bit operation between two variables.
14 | P a g e
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
9. Misc operators in C
It includes operators like sizeof(), reference operator(&), pointer operator(*), condition
operator(?).
Expression Evaluation in C
15 | P a g e
PPS – 3110003 Prepared By: Prof. Jigar Dalvadi
16 | P a g e