#3 Variables and Operators

#3 Variables and Operators - Mapua Institute of Technology...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Mapua Institute of Technology School of IT CS103 Fundamentals of Problem Solving and Programming 1 Lecture #2 Preliminaries, Naming, Types, Operators PRELIMINARIES How does a typical C++ program look like? First, a very simple example of a C program: Example 1: // Sample C program that outputs the word “Hello” #include <iostream> using namespace std; void main (void) { cout<< “Hello\n”; } The program shown in the example above is referred to as a program source code. The source code is made up of a combination of letters, numbers and other symbols. The source code can be created by the programmer/user using any text editor. In the class, we will write C programs using the following format: #include <iostream> using namespace std; void main(void) { ...your variable declarations. .. ...your statements. .. } What is a statement? All C++ programs are made up of a sequence of instructions. In C, instructions are also called statements. In the English language, a period, a question mark or an exclamation point terminates a statement. Note that in C++ language, a semicolon terminates a statement. In the example program above, there is only one statement -- the cout<< statement. Prepared: akdbalan Page 1 of 10
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Mapua Institute of Technology School of IT CS103 Fundamentals of Problem Solving and Programming 1 What is a function? All statements should be written inside a user-defined function. You may think of a function as a group or sequence of statements. It is analogous to the English language wherein a paragraph is made up of a sequence of statements. The word “user-defined” means that it is the user who defined (or wrote) the description of a function. In the example program above, there is only one user-defined function – the main() function. All C++ programs must have a main() function. What is the use of { } symbols? The symbol { is referred to as open brace or open curly bracket. Likewise, the symbol } is called close brace or close curly bracket. The curly brackets are used for grouping purposes. Think of a curly bracket as something synonymous to begin and the close curly bracket as the symbol for end. Thus, in the example program above, the open and close curly brackets designate the beginning and the end of the main() function respectively. Note that the curly brackets must always come in pair. A missing curly bracket is one of the most common causes of syntax errors. As we shall see later on, the curly brackets are used to group several statements. What is the use of // and /* */ symbols? The symbols // and /* */ are used to put comments inside the program. Comments are not instructions; rather they simply provide additional information (a textual description) such as what the program is doing, what are the inputs, what are the outputs etc. // is used for single line comments
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/14/2011 for the course COMPUTER 091 taught by Professor Rajivsir during the Summer '11 term at MIT.

Page1 / 10

#3 Variables and Operators - Mapua Institute of Technology...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online