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

PPS Unit-5

Uploaded by

sayyamverma0027
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)
32 views

PPS Unit-5

Uploaded by

sayyamverma0027
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/ 23

ESE UNIT – 1 AKTU SECOND YEAR

As Per New Syllabus


By
 LAPLACE TRANSFORM
 Linear properties of Laplace LEC : 1
transform

Download
Pdf Notes
Unit -5 Syllabus

Pointers: Introduction, Declaration, Applications, Introduction to Dynamic


Memory Allocation (Malloc, Calloc, Realloc, Free), String and String functions ,
Use of Pointers in Self-Referential Structures, Notion of Linked List (No
Implementation)

File Handling: File I/O Functions, Standard C Preprocessors, Defining and


Calling Macros and Command-Line Arguments.
Pointer

A pointer is a variable that stores the memory address of another variable as its value.
A pointer can be used to store the memory address of other variables, functions, or even
other pointers.

Syntax:
Data_type *pname;
Int *p1;

Example:

int myAge = 43; // An int variable


int* ptr = &myAge; // A pointer variable, name ptr, that stores the address of myAge

printf("%d\n", myAge);
printf("%p\n", &myAge);
printf("%p\n", ptr);
Void Pointer:
A void pointer is a pointer that has no associated data type with it. A void pointer can hold an address of
any type and can be typecasted to any type.

Syntax:
Void *vp;

datatype Pointer name

Why are poiners essential:


• Direct Memory Access
• Dynamic Memory Allocation
• Efficient Array and Data Structure Handling
• Efficient Parameter Passing and Shared Data
• Implementation of Advanced Algorithms
Dynamic Memory Allocation

• Dynamic Memory Allocation refers to the process of allocating or deallocating memory blocks
during a program’s runtime.
• This is achieved through the use of four functions:

• These functions are located in the <stdlib.h> header file.


• Dynamic memory allocation can also be considered a method of utilizing heap
memory
malloc()

• malloc() is the standard library


function used to allocate a
memory block of specified
number of bytes and returns
void pointer.
• The void pointer can be casted
to any datatype. If malloc()
function unable to allocate
memory due to any reason it
returns NULL pointer.
calloc()

• calloc() is the standard library function used to


allocate multiple memory blocks of the
specified number of bytes and initializes them
to ZERO.
• It returns void pointer. If calloc() function unable
to allocate memory due to any reason it returns
a NULL pointer.
• Generally, it is used to allocate memory for
array and structure.
• It function takes two arguments and they are 1.
The number of blocks to be allocated, 2. Size of
each block in bytes
realloc()

• realloc() is the standard library


function used to modify the
size of memory blocks that
were previously allocated using
malloc() or calloc().
• realloc() function returns void
pointer. If calloc() function
unable to allocate memory due
to any reason it returns NULL
pointer.
free()

• free() is the standard library


function used to deallocate
memory block that was previously
allocated using malloc() or calloc().
• free() function returns void pointer.
• When free() function is used with
memory allocated that was created
using calloc(), all the blocks are get
deallocated.
Linked List

• A linked list is a dynamic data structure that consists of a series of nodes connected by
pointers.
• Each node contains data and a reference to the next node in the list.
• Unlike arrays, linked lists allow for efficient insertion or removal of elements from any
position in the list, as the nodes are not stored contiguously in memory.
Types of Linked Lists:
Singly Linked List Doubly Linked List Circular Linked List
• It is the simplest type of linked list • A doubly linked list or a two-way • A circular linked list is that in which
in which every node contains some linked list is a more complex type the last node contains the pointer
data and a pointer to the next of linked list that contains a to the first node of the list.
node of the same data type. pointer to the next as well as the • We can begin at any node and
• The node contains a pointer to the previous node in sequence. traverse the list in any direction
next node means that the node • Therefore, it contains three parts of forward and backward until we
stores the address of the next node data, a pointer to the next node, reach the same node we started.
in the sequence. A single linked list and a pointer to the previous node. Thus, a circular linked list has no
allows the traversal of data only in This would enable us to traverse beginning and no end.
one way. the list in the backward direction
as well.
File Handling

• File handing in C is the process in which we create, open, read, write, and close operations on a file.
• C language provides different functions to perform input, output, and many different C file operations in our program.

Types of Files in C
A file can be classified into two types based on the way the file stores the data. They are as follows:

• Text Files:
 A text file contains data in the form of ASCII characters and is generally used to store a group of characters.
 It can be read or written by any text editor.
 They are generally stored with .txt file extension.

• Binary Files:
 A binary file contains data in binary form (i.e. 0’s and 1’s) instead of ASCII characters.
 More secure as they are not easily readable.
 They are generally stored with .bin file extension.
Operatons on Files:
File Opening Modes:
C program to copy contents of one file to another file
Preprocessor

A preprocessor is a program that processes its input data to produce output that is used as input
in another program.

C Preprocessor Directives:
In almost every C program we come across, we see a few
lines at the top of the program preceded by a hash (#) sign.
They are called preprocessor directives.
They are preprocessed by the preprocessor before actual
compilation begins.

Types of Preprocessor Directives in C:


There are mainly three types of preprocessor directives:
1.Macro Definition
2.File Inclusion directive
3.Conditional Compilation
1. #define – Macro Directive
• A macro is a piece of code in a program that is replacd by the value of the macro.
• Macro is defined by #define directive.

Example -
Defining a macro
Using
#define
2. #include – File Inclusion Directive

• #include preprocessor directive is used to include the content of one file to


another file

• Syntax: #include <file_name>


or
#include "filename"
File inclusion with double quotes ( ” ” ) tells the compiler to search for the header
file in the directory of source file.

Example - File
inclusion
directives
3. #if, #ifdef, #else, #elfi, #endif – Conditional Compilation:

If we write program normally means using simply if else and so on


so your complete code is compiled by compiler and on execution
time only those statement satisfied the condition will execute but
in condition compilation, according to condition some set of
instruction compiled #if, #ifdef, #ifndef, #else, #elif , #endif
Conditional Compilation Code demonstration:
Difference between MACRO and FUNCTION:
THANK YOU 👍

You might also like