Skip to content

devinenoise/cpp-data-structures

 
 

Repository files navigation

Data Structures

Data structure is the way you organize data in the main memory during execution of a program.

Arrays

An array is a collection of similar data elements.

Declaration : int A[5];

Initialization : int B[5]={2,4,6,8,10};

If you have an array of some size and don't define the elements they will become zero by default.

Structures

A structure is a collection of data members that are related under one name.

  1. Defining a structure

struct Rectangle { int length; int width; };

  1. Size of a structure

The total size of a structure is the sum of its element in memory. An int is 4 bytes.

  1. Declaring a structure

struct Rectangle r;

struct Rectangle r={10,15} with initialization

  1. Accessing members

Members are accessed with dot operators.

r.length = 15; r.width = 10;

Pointers

Releases

No releases published

Packages

No packages published

Languages