Data Structures

DS – Introduction

Introduction: Banking Application – Store customers information and transactions information.Customers use Banking application to communicate with Banking Employee. How to store information in application? Primitive variable: Array variable: Structure variable: stores more than one value of different data types. We define structures using struct keyword struct Employee{            int id;            char name[20];            float salary;};struct Employee e …

DS – Introduction Read More »

DS – Memory Allocation

Static v/s Dynamic memory: Note the following: Static memory: Static Memory allocate to Arrays, Strings and Structures: The following diagram represents static memory allocation: Dynamic memory:

DS – Functions in C

Variable: Stores data. Function: Performs operation on data. Function takes input, performs operations and returns output Syntax Example int identity(arguments)             {                         -> statements;             } int add(int a, int b)             {                         int res = a+b ;                         return res ;             } C functions classified into: Built in Functions: stdio.h conio.h …

DS – Functions in C Read More »

DS – Arrays in C

Primitive type: int main(){            int a=5;            a=10;            a=20;            printf(“a val : %d \n”, a);   // prints – 20            return 0;} Array: Array creation: Process Array elements: How to access array elements? Reading Printing int i;for(i=0 ; i<5 ; i++){            scanf(“%d”, &marks[i]);} int i;for(i=0 ; i<5 ; i++){            printf(“%d”, marks[i]);} Length of array: int main(){            …

DS – Arrays in C Read More »

DS – Strings in C

String: Syntax:             char identity[size]; Example:             char name[20]; Memory representation: String Format Specifier(%s): Program to display String: #include<stdio.h>int main(){            char str[20] = “Hello” ;            printf(“%s all \n” , str);             return 0;} strlen() : strlen() returns length of string excluding null character. #include<string.h>int main(){            char str[20];            size_t len;            printf(“Enter string : “);            gets(str);            len = …

DS – Strings in C Read More »

DS – Structures in C

Introduction: Primitive variable: Array variable: Structure variable: stores more than one value of different data types. We define structures using struct keyword struct Employee{            int id;            char name[20];            float salary;};struct Employee e = {101, “Amar”, 35000}; Array of Structures: used to store more than one record details. struct Employee{            int id;            char name[20];            float salary;};struct …

DS – Structures in C Read More »

DS – Pointers in C

Introduction: Pointers classified into: Operators using with Pointers: Following program explains the memory representation of pointer variables: CALL BY VALUE & CALL BY REFERENCE Call by value: A copy of the variable is passed to the function. Call by reference: An address of the variable is passed to the function. Note: Call by reference is …

DS – Pointers in C Read More »

DS – Dynamic Memory Allocation in C

Memory Allocation in C: stdlib.h: Pointer casting: #include<stdio.h>int main(){            int x=10;            int* p1;            char* p2;                       p1 = &x;            printf(“x value is : %d \n”, *p1);                       p2 = (char*)p1;            printf(“x value is : %d \n”, *p2);            return 0;          } size_t: malloc(): Why return type is void*? Program to allocate memory dynamically to structure: #include<stdio.h>struct Emp{            int id;            …

DS – Dynamic Memory Allocation in C Read More »

DS – Stack Data Structure

Stack: Note: We create Stack using arrays, only the way of representation and Rules of accessing elements vary. Array Stack Linear data structure Linear data structure Process elements using Index Process element using TOP Insert element any where Insert at top only Delete element from any where Delete from top Display element in any format …

DS – Stack Data Structure Read More »

Scroll to Top