0% found this document useful (0 votes)
40 views

Data Flow Diagram

The document discusses data flow diagrams (DFDs), subprograms, function parameters, scope of variables, and functions in C programming. It provides definitions and examples of: - DFDs which graphically represent data flow and have two types - logical and physical. Logical DFDs focus on processes while physical are more specific to implementation. - Subprograms which are reusable blocks of code that can be procedures or functions. Procedures represent computations while functions evaluate to a value. - Function parameters which can be passed by value, where the parameter is copied, or by reference, where the address is copied. Scope of variables determines where a variable name can be accessed within the program. -

Uploaded by

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

Data Flow Diagram

The document discusses data flow diagrams (DFDs), subprograms, function parameters, scope of variables, and functions in C programming. It provides definitions and examples of: - DFDs which graphically represent data flow and have two types - logical and physical. Logical DFDs focus on processes while physical are more specific to implementation. - Subprograms which are reusable blocks of code that can be procedures or functions. Procedures represent computations while functions evaluate to a value. - Function parameters which can be passed by value, where the parameter is copied, or by reference, where the address is copied. Scope of variables determines where a variable name can be accessed within the program. -

Uploaded by

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

UNIT-V

Data Flow Diagram (DFD)


Data Flow Diagram is a graphical representation of data flow in any system. It is capable of illustrating
incoming data flow, outgoing data flow and store data. Data flow diagram describes anything about how
data flows through the system.
Sometimes people get confused between data flow diagram and flowchart. There is a major difference
between data flow diagram and flowchart. The flowchart illustrates flow of control in program modules.
Data flow diagrams illustrate flow of data in the system at various levels. Data flow diagram does not
have any control or branch elements.
Types of DFD:
DFD is of two types:
1. Logical DFD:
Logical data flow diagram mainly focuses on the system process. It illustrates how data flows in the
system. Logical DFD is used in various organizations for the smooth running of system. Like in a
Banking software system, it is used to describe how data is moved from one entity to another.
2. Physical DFD:
Physical data flow diagram shows how the data flow is actually implemented in the system. Physical
DFD is more specific and close to implementation.
Symbols of Data Flow Diagram:
Following are the components of the data flow diagram that are used to represent source, destination,
storage and flow of data.

 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

 A subprogram has a single entry point.


 The caller is suspended during the implementation of the called subprogram.
 Control repeatedly returns to the caller when the called subprogram’s execution eliminates.

Types of Subprograms

 Procedures − A procedure is defined as a subprogram that defines parameterized computations.


These computations are executed by an individual call statement. Procedures represent new
statements. For example, because Pascal does not have a sort statement, a user can develop a
procedure to sort arrays of records and use a call to that procedure in place of the unavailable sort
statement.
 Functions − A function is a subprogram that evaluates a value. Functions and procedures are
structured identical, except that
o Functions are semantically modeled on mathematical functions.
o Functions have a RETURN clause.
o Functions produce no side effects i.e., it changes neither its parameters nor any variables
defined outside the function.
Value and Reference Parameters
Call by Reference
The call by reference method of passing arguments to a function copies the address of an argument into
the formal parameter. Inside the function, the address is used to access the actual argument used in the
call. It means the changes made to the parameter affect the passed argument.
#include <stdio.h> Output
int main ()
{ Before swap: 100
int a = 100; Before swap: 200
int b = 200; After swap: 200
printf("Before swap: %d\n", a ); After swap: 100
printf("Before swap: %d\n", b );
swap(&a, &b);
printf("After swap: %d\n", a );
printf("After swap: %d\n", b );
return 0;
}
void swap(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
return;
}

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

#include <stdio.h> x = 10, y = 20


int main() x = 11, y = 41
{
{
int x = 10, y = 20;
{
printf("x = %d, y = %d\n", x, y);
{
int y = 40;
x++;
y++;
printf("x = %d, y = %d\n", x, y);
}
}
return 0;
}

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 function_name( parameter list ) int max(int num1, int num2)


{ {
body of the function int result;
} if (num1 > num2)
result = num1;
else
result = num2;
return result;
}

 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()

Creating or opening file using fopen()


The fopen() function is used to create a new file or open an existing file in C. The fopen function is defined
in the stdio.h header file.
Syntax
file = fopen(“file_name”, “mode”)
Closing a File
The file (both text and binary) should be closed after reading/writing. Closing a file is performed using the
fclose() function.
Syntax
fclose(fptr);
Here, fptr is a file pointer associated with the file to be closed.

Reading and writing to a text file


For reading and writing to a text file, we use the functions fprintf() and fscanf(). They are just the file
versions of printf() and scanf(). The only difference is that fprintf() and fscanf() expects a pointer to the
structure FILE.
Reading and writing to a binary file
Functions fread() and fwrite() are used for reading from and writing to a file on the disk respectively in case
of binary files.
Writing to a binary file
To write into a binary file, you need to use the fwrite() function. The functions take four arguments:
 address of data to be written in the disk
 size of data to be written in the disk
 number of such type of data
 pointer to the file where you want to write.
Syntax
fwrite(addressData, sizeData, numbersData, pointerToFile);
Reading from a binary file
Function fread() also take 4 arguments similar to the fwrite() function as above.
Syntax
fread(addressData, sizeData, numbersData, pointerToFile);

Mod
Meaning of Mode During Inexistence of file
e

If the file does not exist, fopen()


r Open for reading.
returns NULL.

If the file does not exist, fopen()


rb Open for reading in binary mode.
returns NULL.

If the file exists, its contents are


overwritten.
w Open for writing.
If the file does not exist, it will be
created.

If the file exists, its contents are


overwritten.
wb Open for writing in binary mode.
If the file does not exist, it will be
created.

Open for append. If the file does not exist, it will be


a
Data is added to the end of the file. created.

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.

If the file does not exist, fopen()


r+ Open for both reading and writing.
returns NULL.

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

If the file exists, its contents are


overwritten.
w+ Open for both reading and writing.
If the file does not exist, it will be
created.

If the file exists, its contents are


Open for both reading and writing in overwritten.
wb+
binary mode. If the file does not exist, it will be
created.

If the file does not exist, it will be


a+ Open for both reading and appending.
created.

Open for both reading and appending in If the file does not exist, it will be
ab+
binary mode. created.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy