Data Flow Diagram
Data Flow Diagram
Entities
Entities include source and destination of the data. Entities are represented by rectangle with their
corresponding names.
Process
The tasks performed on the data is known as process. Process is represented by circle. Somewhere
round edge rectangles are also used to represent process.
Data Storage
Data storage includes the database of the system. It is represented by rectangle with both smaller sides
missing or in other words within two parallel lines.
Data Flow
The movement of data in the system is known as data flow. It is represented with the help of arrow.
The tail of the arrow is source and the head of the arrow is destination.
Program Modules
Subprogram
A subprogram is defined as a set of statements that can be reused at multiple places in a program when
convenient. This reuse results in multiple types of savings, from memory space to coding time. Such reuse is
also an abstraction, for the analysis of subprograms computations are restored in a program by a statement
that calls the subprogram.
Features of Subprograms
Types of Subprograms
Call by value
The call by value method of passing arguments to a function copies the actual value of an argument into
the formal parameter of the function. In this case, changes made to the parameter inside the function have
no effect on the argument.
By default, C programming uses call by value to pass arguments. In general, it means the code within a
function cannot alter the arguments used to call the function.
#include <stdio.h> Output
void swap(int x, int y);
int main () Before swap: 100
{ Before swap: 200
int a = 100; After swap: 100
int b = 200; After swap: 200
printf("Before swap, value of a : %d\n", a );
printf("Before swap, value of b : %d\n", b );
swap(a, b);
printf("After swap, value of a : %d\n", a );
printf("After swap, value of b : %d\n", b );
return 0;
}
void swap(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
return;
}
Scope of a variable
The scope of a variable in C is the block or the region in the program where a variable is declared,
defined, and used. Outside this region, we cannot access the variable and it is treated as an undeclared
identifier.
The scope is the area under which a variable is visible.
The scope of an identifier is the part of the program where the identifier may directly be accessible.
We can only refer to a variable in its scope.
Types of Scope
C scope rules can be covered under the following two categories:
1. Global Scope
2. Local Scope
Let’s discuss each scope rule with examples.
1. Global Scope
The global scope refers to the region outside any block or function.
The variables declared in the global scope are called global variables.
Global variables are visible in every part of the program.
Global is also called File Scope as the scope of an identifier starts at the beginning of the file and
ends at the end of the file.
Example Output
#include <stdio.h>
int global = 5; Before change: 5
void display() After change: 10
{
printf("%d\n", global);
}
int main()
{
printf("Before change: ");
display();
printf("After change: ");
global = 10;
display();
}
2.Local Scope
The local scope refers to the region inside a block or a function. It is the space enclosed between the { }
braces.
The variables declared within the local scope are called local variables.
Local variables are visible in the block they are declared in and other blocks nested inside that
block.
Local scope is also called Block scope.
Local variables have internal linkage.
Example Output
Function
A function is a group of statements that together perform a task. Every C program has at least one function,
which is main(), and all the most trivial programs can define additional functions.
Defining a Function
Syntax Example
Return Type − A function may return a value. The return_type is the data type of the value the
function returns. Some functions perform the desired operations without returning a value. In this
case, the return_type is the keyword void.
Function Name − This is the actual name of the function. The function name and the parameter list
together constitute the function signature.
Parameters − A parameter is like a placeholder. When a function is invoked, you pass a value to
the parameter. This value is referred to as actual parameter or argument. The parameter list refers
to the type, order, and number of the parameters of a function. Parameters are optional; that is, a
function may contain no parameters.
Function Body − The function body contains a collection of statements that define what the
function does.
Function arguments
Basically, there are two types of arguments:
Actual arguments
Formal arguments
The variables declared in the function prototype or definition are known as Formal arguments and the
values that are passed to the called function from the main function are known as Actual arguments.
The actual arguments and formal arguments must match in number, type, and order.
Recursion
Recursion is the process of calling a function itself repeatedly until a particular condition is met. A
function that calls itself directly or indirectly is called a recursive function and such kind of function
calls are called recursive calls.
syntax Example Output
type function_name(args) #include<stdio.h> 0
{ int fibonacci(int i) 1
// function statements { 1
// base condition if(i == 0) 2
// recursion case (recursive { 3
call) return 0; 5
} } 8
if(i == 1) 13
{ 21
return 1; 34
}
return fibonacci(i-1) +
fibonacci(i-2);
}
int main()
{
int i;
for (i = 0; i < 10; i++)
{
printf("%d\t\n",
fibonacci(i));
}
return 0;
}
File Basics
File is a collection of records placed or store on computers storage devices like hard disk.
A file is a container in computer storage devices used for storing data.
Why files are needed?
When a program is terminated, the entire data is lost. Storing in a file will preserve your data even if
the program terminates.
If you have to enter a large number of data, it will take a lot of time to enter them all.
However, if you have a file containing all the data, you can easily access the contents of the file
using a few commands in C.
You can easily move your data from one computer to another without any changes.
Types of Files
Text files
Binary files
1. Text files
Text files are the normal .txt files. You can easily create text files using any simple text editors such
as Notepad.
When you open those files, you'll see all the contents within the file as plain text. You can easily edit
or delete the contents.
They take minimum effort to maintain, are easily readable, and provide the least security and takes
bigger storage space.
2. Binary files
Binary files are mostly the .bin files in your computer.
Instead of storing data in plain text, they store it in the binary form (0's and 1's).
They can hold a higher amount of data, are not readable easily, and provides better security than text
files.
File Operations
File operations refer to the different possible operations that we can perform on a file in C such as:
1. Creating a new file – fopen() with attributes as “a” or “a+” or “w” or “w+”
2. Opening an existing file – fopen()
3. Reading from file – fscanf() or fgets()
4. Writing to a file – fprintf() or fputs()
5. Moving to a specific location in a file – fseek(), rewind()
6. Closing a file – fclose()
Mod
Meaning of Mode During Inexistence of file
e
Open for append in binary mode. If the file does not exist, it will be
ab
Data is added to the end of the file. created.
Open for both reading and writing in If the file does not exist, fopen()
rb+
binary mode. returns NULL.
Mod
Meaning of Mode During Inexistence of file
e
Open for both reading and appending in If the file does not exist, it will be
ab+
binary mode. created.