Computer Science Programming Basics Easy

In Basics of Programing, there are some topics that you need to Understand.

Variables

Let us relate them to old mathematical equations. All of us have solved many mathematical equations since childhood. As an example, consider the below equation

2x + 2y- 2 = 1 

We don’t have to worry about the use of this equation. The important thing that we need to understand is that the equation has names (x and y), which hold values (data ). That means the names (x and y) are placeholders for representing data. Similarly, in computer science programming we need something for holding data, and variables are the way to do that.

Data Types

In the above-mentioned equation, the variables x and y can take any values such as integral numbers (x = 10, y = 20), real numbers (x = 0.23, y = 5.5), or just x=0 and y=1. To solve the equation, we need to relate them to the kind of values they can take, and data type is the name used in computer science programming for this purpose. A data type in a programming language is a set of data with predefined values. Examples of data types are integer, floating-point, unit number, character, string, etc.

Computer memory is all filled with zeros and ones. If we have a problem and we want to code it, it’s very difficult to provide the solution in terms of zeros and ones.

To help users, programming languages and compilers provide us with data types. For example, integer takes 2 bytes (actual value depends on the compiler of Programing Language), float takes 4 bytes, etc. This says that in memory we are combining 2 bytes (16 bits) and calling it an integer. Similarly, combining 4 bytes (32 bits) and calling it a float. A data type reduces the coding effort. At the top level, there are two types of data types:

  • System-defined data types (also called Primitive data types)
  • User-defined data types

Primitive Data Types

The Data types, which are defined by System called primitive data types. The primitive data types provided by many programming languages are int, float, char, double, bool, etc. The number of bits allocated for each primitive data type depends on the programming languages, the compiler, and the operating system. for the same primitive data type, different languages may use different sizes. Depending on the size of the data types, the total available values (domain) will also change in Programing.

For Example in Java Int takes 4 Byte to store data it can be: 0 ,1, -1, 2, 100

User-Defined Data Types

If the system-defined data types are not enough, then most programming languages allow the users to define their own data types, called user-defined data types. Good examples of user-defined data type arc: structures in C/C + + and classes in Java.

struct newTypc {
  int data1;
  float data2;
  ...
  char data;
}; 

Data Structures

Now we have Variable and Data Types, We need some mechanism for manipulating that data to solve problems. The data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. A data structure is a special formula for organizing and storing data.

General data structure types include arrays, files, linked lists, stacks, queues, trees, graphs, and so on. Depending on the organization of the elements, data structures are classified into two types:

  1. Linear data structures: Elements are accessed in sequential order but it is not compulsory to store all elements sequentially. Examples: Linked Lists, Stacks, and Queues.
  2. Non-Linear data structures: Elements of this data structure arc stored /accessed in a non-linear order. Examples: Trees and graphs.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on whatsapp
WhatsApp
Share on reddit
Reddit
Share on telegram
Telegram

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top