Programming Concepts : 01. Program Structure and Variables

A computer program is a set of statements that make the computer preforms an action or interact with user or the computer hardware and apply a specified task. All computer programs are mainly consisting of :

  1. Headers / The start of the program.
  2. Variables.
  3. Statements and flow controllers (Code Blocks).
Simple C# application

Simple C# application

 Variables :

Variables are simply places in memory that a program can use to store data and read it later. Variables are given names like ‘x’ , ‘salary’, so you can refer to them later using them instead of ugly memory pointers and locations. Each variable must be assigned to a specific data type, so to declare a variable we need to choose a data type , name and assign a value to it (Optional).

” There are two types of variables , we have static variables in which memory is reserved during compilation time.In contrast, dynamic variables addresses are determined when the program is run.”

Common data types:

Data type Description Example
Integers Finite subset of mathematical integers. int x = -1
Booleans Logical data type (true or false) bool flag=true;
Characters Represents a symbol of natural language char a = ‘a’
floating-point Represents numbers with integral and fractional parts. float x = 1.5
String sequence of characters string name = “Ahmed”

These are only the common data types, programming languages provides a large variety of data types like byte,double,long. There are more and more, just search and you will find them easily.

Variables aren’t the only data structure that programming languages provide, more complex data structures are available like arrays, lists, tuples and dictionaries. 

Arrays :

An array is a container object that holds a fixed number of values of a single type. – Oracle Java tutorials

arrays could be one dimensional arrays “Vectors” like ({1,2,3,4,5,6}) or they can be multidimensional arrays “Matrices” like ({{1,2},{3,4},{5,6}}. We use “indexes” to access an element in an array like (arr_name[1]).

Example :

string[] students = {“Ahmed”,”Karim”,”Ali”};

Console.WriteLine(students[0] + ” ” + students[2]); //prints out the line Ahmed Ali.

Arrays are usually zero indexed, that means that for an (n) vector we have (0,1,2,3, …. ,n-1) range of indexes.

Associative array (Dictionary) :

This type of data structure is just like arrays, yet the index here is not and integer ranges from(0 to n-1), yet this array are composed of pairs represented like this (Key, Value). We index a dictionary with keys and use them to retrieve the corresponding values.


Dictionary<string, string> facColors = new Dictionary<string, string>();

favColors.Add(“Ali”,”Red”); favColors.Add(“Ahmed”,”Blue”);

Console.WriteLine(favColors[“Ahmed”]); //prints out the word Blue

There are more advanced data structures, each programming language offer it’s own set of those data structures, but you can also implement any data structure you want in any language that doesn’t provide it by default. These data structures are like linked lists, queues, graphs, stacks , etc.

I won’t be talking about these as they differ from language to another, so i’ll leave this to your choice of language and researches.

The next post we will be talking about boolean algebra , comparison operators and conditional statements.


2 thoughts on “Programming Concepts : 01. Program Structure and Variables

    • Array of arrays .. like this in python:
      print(names[0][1]) #prints ahmed
      print(names[1][0]) #print Asmaa

      so you simply deal with it as every element is an array(vector) and then access every element in it..
      This will be explained later when we finish concepts and start in C# 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s