Back to: C++ Tutorials For Beginners and Professionals
Computers Programs and how they work
In this article, I am going to give a brief introduction to Computers Programs and how they work. This article mainly focuses on the basics of computers, which are needed before learning any programming language. If you are a new/beginner to computer programming then please go through this introduction section as it gives more clarity on how the computer thinks. Why do we need programming language etc. But if you have prior experience in programming then you can skip this article. The topics covered in this article are as follows which are related to computers and Programs:
- What is a program?
- What are compiler and interpreter?
- What is an operating system?
- Introduction to Number System?
What is a Program?
We already talked about the program files in our previous explanation. Here let us talk about what exactly a program means. A program is just an instruction to a computer to perform a specific task. For Example, I instruct my computer to open the application, close the application, etc.
Student: Hey Teacher… you said the program is an instruction to a computer and you also said the computer thinks in binary 0’s and 1’s but I am learning here is C++ which from syntax, wise similar to English. I feel awkward about your explanation.
Teacher: Hey wait, I think you are in hurry…! Can you talk with the computer in 0’s and 1’s?
Teacher: Then can you teach a machine English?
Student: NO. From your explanations what I understand is the computer can only understand 0’s and 1’s just like me I understand only English.
Teacher: That is why we need compilers and interpreters when we talk with computers.
Let us take an example to understand this better:
Teacher: suppose you have a client from Spain who knows only Spanish and you know only English how you interact with them.
Student: I appoint a translator when I had a meeting with the Spain client where he/she could translate for me and vice-versa.
Author: Exactly the same thing happens in the case of Computers also. Computers cannot learn our language or we cannot learn the computer language. So, we need a translator who could translate our instructions to the computer and vice versa. Compilers and Interpreters Act as a translator here.
Compiler and Interpreter:
From Definition Compilers and Interpreters transform code written in High-level language (Human understandable language) to Machine Code (Binary code or Machine understandable language).
From the Interview Point of View and Exam Point of View, it is important to know the difference between Compiler and Interpreter.
The compiler translates High-level code (Source code) to Machine code All at once.
Let us take an example: Say you have written a program in a high-level language that does simple arithmetic operations like addition, multiplication, etc. When you give this program to the compiler, the compiler translates all the instructions written in the program to machine code. Then after it gives a full-translated machine code to computers.
Advantage: It is faster when compared to the interpreter as the entire translation happens in one go.
The interpreter translates each High-level instruction to machine code One by one.
We can take the above example, which we used, for compilers. When we give the program to the interpreter, it translates the first instruction and generates the machine code, and gives it to the computer. Thereafter second instruction translation and goes on until all the instructions were converted to machine code.
Advantage: If there is a problem in one instruction then the program will be executed till the previous instruction.
Difference between Compilers and Interpreters:
Operating System (OS) is a master program, which uses all available resources of the computer, and provides a service to the end-user.
Student: OS is a program? But I never ran the OS or I never instructed the computer to run this master program.
Teacher: Yes, OS is also an instruction maybe you can call it a bunch of instructions to the computer. This is the program that gets autoloaded when you trigger the switch on the button of your PC (which means it is an auto-loaded program).
To run any program or instruction in the main memory or on the computer you need a master program that got loaded to the main memory so that it handles all the resources like HDD, Keyboard monitor, etc. In addition, this program runs in the main memory unless you trigger it to shut down on your computer.
Commonly used OS for PC are Linux, windows, and mac.
Commonly used OS for mobile are Android, windows, and ios.
Before Jumping to the next Topic, let us know the difference between High-level code (program) and low-level Code.
Difference between High-level Program and low-level Code
In the next article, I am going to give a brief introduction to the C++ Programming language. Here, in this article, I try to give a brief introduction to computers and Programs and how they work and I hope you enjoy this introduction to computers and Programs and how they work article.