Module-1 3

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Department of Computer Science & Engineering

IOT
Global Campus: 45th km NH - 209 Jakkasandra Post, Kanakapura Rd, Bengaluru, Karnataka 562112

DATA STRUCTURES
What is a data structure ?
• Computers are basically data processing machines.
• The system input is raw data and the output is the processed data.
• Therefore, data structure is the way of organizing or structuring data in a
computer.
• All computational paradigms need data to perform computations or solve a
problem.
• So here, we are discussing about the different data structures available in C
programming lamguage.
What is C programming
•language ?
C language performs problem solving or computations using algorithms and
data structures.
• C is a high level programming language.
• In the compiling and interpretation process, C code is converted into machine
code or machine level language, where it is finally executed by the CPU.
• C has it’s own support for the types of data or data structures, using which it
performs computations.
• Finally, C language is a programming language used to solve and kind of
problem by instructions given to the computer, using C.
What is a function ?
• A function is an instruction block or piece of code that performs computation
on the data, using data structures.
• There are different types of functions in C programming language.
• The three aspects of a function in C programming language are:
1. Function declaration – It is the basic step, here we declare the function.
2. Function call – Since functions are basic building blocks of a program, it can
be called anytime.
3. Function definition – Here we define the type of function, based on it’s
parameter or argument type or by the type of function itself.
Example of a function in
C:
Another example C
program:
Function parameters type:
• Pass by value.
Pass by reference:
Recursive functions:
• A recursive function is a function that calls itself, definitely or indefinitely.
• Due to this, the lines of repetitive code gets reduced and hence the total
number of lines in the whole program optimises, thus reducing the execution
time and execution complexity.
Recursive function in C.
Returning a function value in
•C.
In C, functions return values to main functions to make the computations
faster and more easy to compile.
• Due to this, there is no need to perform a functional computation again and
again.
• Remember in C, returning a functional value can be used for any kind of
function.
• If a function does not return any value, then the VOID return type is used
for
the function.
Returning a value in
C:
Scope rule of a function in
C:
There are three scope rules for a function in C:
1. Local scope.
2. Global scope.
3. Formal scope.
Local scope:
• In the local scope, variables are declared inside a function and the value of the
function is only within this function, in which this is declared.
Global scope:
• Here the globally declared variable can be used anywhere within the C
program.
• Once it is declared globally, there is no need to declare it again within the
main function.
• This is the difference between local and global scope.
Global scope:
Formal scope:
• In formal scope, the scope of the global variable declared will be override by
the value explicitly declared inside the main function.
Storage classes in
C:
Auto storage class in
C: is the default storage class in C. The value of this storage class depends
Auto
to
the local scope to which the variable is declared or initialized to.
Register storage class in
•C:
If we declare a variable as register in C, they are stored inside the register of
the central processing unit and they cannot be manipulated.
• This is a hardware concept and therefore the declaration depends on the
hardware configuration of the computer.
• They can be used along with pointers. Then it will have the address of the
memory location.
Register variable in
C:
Extern keyword in C.
• The extern keyword or storage class in C is used to declare global variables in
header files or variables in C, that have no memory associated with them.
• The extern keyword is just like register, but the difference is, instead of
getting stored in registry, this is stored as an external variable.
Extern storage class.
• Scope − They are not bound by any function. They are everywhere in the program i.e.
global.
• Default value − Default initialized value of global variables are Zero.
• Lifetime − Till the end of the execution of the program.
Static storage class in
C.
• datatype − The datatype of variable like int, char, float etc.
• variable_name − This is the name of variable given by user.
• value − Any value to initialize the variable. By default, it is
zero.
Libraries in
•C.
Standard C Library Functions Table, By Name - IBM Documentation
• They contain the set of standard library functions.
• They are pre-defined and their functionality need not be again defined in the
program that we write.
• There is no limit to the number of header files that can be used in C.
• The pre-processor directive in C, can be invoked by using the keyword
“#include”.
• All header library files have the extension “.h”. This is same for all libraries in C.

You might also like