Dsappt
Dsappt
ADVANTAGE OF C ARRAY
1) CODE OPTIMIZATION :-Less code to the access the data.
2) EASE OF SORTING :-By using the for loop, we can retrieve the elements of an array easily
3) EASE OF TRAVERSING :-To sort the elements of the array, we need a few lines of code only
4) RANDOM ACESS :-We can access any element randomly using the array.
DECLARATION OF C ARRAY
data_type array_name[array_size];
CONTENTS
• POINTERS :-
The pointer in C language is a variable which stores the address of another
variable. This variable can be of type int, char, array, function, or any other
pointer.
DECLARING A POINTER
int *a;//pointer to int
char *c;//pointer to char
CONTENTS
• Pointer to array
int arr[10];
Int *p[10]=&arr; // Variable p of type pointer is pointing to the address of an integ
er array arr.
Pointer to a function:-
1.void show (int);
2.void(*p)(int) = &display; // Pointer p is pointing to the address of a function
3.Pointer to structure:- struct st {
int i;
float f;
}ref;
struct st *p = &ref;
CONTENTS
• Advantage of pointer:-
1) Pointer reduces the code and improves the performance, it is used to
retrieving strings, trees, etc. and used with arrays, structures, and
functions.
2) We can return multiple values from a function using the pointer.
3) It makes you able to access any memory location in the computer's
memory.
CONTENTS
• Usage of pointer
1) Dynamic memory allocation:- we can dynamically allocate memory
using malloc() and calloc() functions where the pointer is used.
2) Arrays, Functions, and Structures:-Pointers in c language are widely
used in arrays, functions, and structures. It reduces the code and
improves the performance.
CONTENTS
• C Structure:-Structure in c is a user-defined data type that enables us to store the
collection of different data types. Each element of a structure is called a member.
Structures ca; simulate the use of classes and templates as it can store various
information
1.Syntax struct structure_name
{
data_type member1;
data_type member2;
.
.
data_type memeberN;
};
CONTENTS
• Memory allocation of the structure
CONTENTS
• File Handling in C:-
File handling in C enables us to create, update, read, and delete the
files stored on the local file system through our C program. The
following operations can be performed on a file:-
1) Creation of the new file
2) Opening an existing file
3) Reading from the file
4) Writing to the file
5) Deleting the file
CONTENTS
• Opening File: fopen()
SYNTAX:-
FILE *fopen( const char * filename, const char * mode );
• Closing File: fclose()
SYNTAX:- int fclose( FILE *fp );
• writing file :C fprintf() and fscanf()
SYNTAX:-
int fprintf(FILE *stream, const char *format [, argument, ...])
• Reading File : fscanf() function
SYNTAX :-int fscanf(FILE *stream, const char *format [, argument, ...])
CONTENTS
• DSA:- The term DSA stands for Data Structures and Algorithms. As
the name itself suggests, it is a combination of two separate yet
interrelated topics – Data Structure and Algorithms.
DATA STRUCTURE :- A data structure is defined as a particular
way of storing and organizing data in our devices to use the data
efficiently and effectively.