Maria Regina C. Flores Instructor WHAT IS MACHINE LANGUAGE? Machine code also known as machine language, is the elemental language of computers, comprising a long sequence of binary digital zeros and one (bits). 00000 10011110 00001 11110100 00010 10011110 00011 11010100 00100 10111111 00101 00000000 WHAT IS HIGH LEVEL LANGUAGE? High-level languages enables programmers to write programs that are more or less independent of a particular type of computer. Such languages are considered high-level because they are closer to human languages and further from machine language. 1 int a, b, sum; 2 3 cin >> a; 4 cin >> b; 5 6 sum = a + b; 7 cout << sum << endl; Programs written in high-level languages must be translated into machine language by a compiler or interpreter. WHAT IS A COMPILER? It is a computer software that transforms computer code written in one programming language (the source language).
The name compiler is primarily used for programs
that translate source code from a high-level programming language to a low-level language(ex. Machine code/machine language) to create an executable program. Compiler checks whether the program follows the C++ syntax if it finds errors, it lists them If there are no errors, it translates the C++ program into a program in machine language which you can execute WHAT IS A COMPILER? This is a portion of code written in C++ that accomplishes the exact same purpose: 1 int a, b, sum; 00000 10011110 2 00001 11110100 3 cin >> a; 00010 10011110 4 cin >> b; COMPILER 5 00011 11010100 6 sum = a + b; 00100 10111111 7 cout << sum << endl; 00101 00000000 YOUR FIRST PROGRAM The best way to learn a programming language is by writing programs. Typically, the first program beginners write is a program called "Hello World", which simply prints "Hello World" to your computer screen. Although it is very simple, it contains all the fundamental components C++ programs have: #include is a “pre-processor” directive that tells the compiler to put code from the header called iostream into our program before actually creating the executable. By including header files, you gain access to many different functions, for example the cout function requires iostream. This line tells the compiler to use a group of functions that are part of the standard library (std). By including this line at the top of the file, you allow the program to use functions such as cout. The function named main is a special function in all C++ programs; it is the function called when the program is run. The execution of all C++ programs begins with the main function, regardless of where the function is actually located within the code. { and } Everything between these braces is the function's body that defines what happens when main is called. All functions use braces to indicate the beginning and end of their definitions. This line is a C++ statement. A statement is an expression that can actually produce some effect. cout – means character output << - indicates that what follows is inserted into cout. "Hello world!" - the content inserted into the standard output. ; - This character marks the end of the statement, just like as the period ends a sentence in English.