Professional Documents
Culture Documents
C++ Introd
C++ Introd
development environment.
Phase 4: Linking
Phase 4 is called linking. C++ programs typically contain references to functions and data
defined elsewhere, such as in the standard libraries or in the private libraries of groups of
programmers working on a particular project. The object code produced by the C++
compiler typically contains “holes” due to these missing parts. A linker links the object code
with the code for the missing functions to produce an executable program (with no missing
pieces). If the program compiles and links correctly, an executable image is produced
Phase 5: Loading
Phase 5 is called loading. Before a program can be executed, it must first be placed in
memory (Fig. 1.10). This is done by the loader, which takes the executable image from
disk and transfers it to memory. Additional components from shared libraries that support
the program are also loaded.
Phase 6: Execution
Finally, the computer, under the control of its CPU, executes the program one instruction
at a time (Fig. 1.11). Some modern computer architectures can execute several instructions
in parallel.
Welcome to C++!
Fig. 2.1 | Text-printing program.
Comments
Lines 1 and 2
Line 6
int main()
is a part of every C++ program. The parentheses after main indicate that main is a program
building block called a function. C++ programs typically consist of one or more functions
and classes (as you’ll learn in Chapter 3). Exactly one function in every program must be
named main. Figure 2.1 contains only one function. C++ programs begin executing at
function main, even if main is not the first function in the program. The keyword int to
the left of main indicates that main “returns” an integer (whole number) value
The left brace, {, (line 7) must begin the body of every function. A corresponding
right brace, }, (line 11) must end each function’s body.
An Output Statement
Line 8
std :: cout << "Welcome to C++!\n"; // display message
\r Carriage return. Position the screen cursor to the beginning of the current line; do not
advance to the next line.
\a Alert. Sound the system bell.
‘\a’:
‘a’ stands for alarm. It causes a beep sound on the computer.
‘\b’:
‘b’ stands for backspace. It moves the cursor one space back. For
example, a statement is given below using ‘\b’ escape sequence.
Cout<<”welcome\b”;
After execution of this statement, the string “welcome” will be
printed and the cursor will move one space back. It means that it
will be under the character ‘e’ of the word “welcome”. In the above
statement if ‘\b’ is omitted, then the cursor will be at the end of the
string. If another output statement is used after the above
statement, then the printing will be started from character ‘e’ and
‘e’ will be deleted.
Cout<<”\’welcom\’”;
The output will be as under:
‘welcome’
For Example
cout<<"*\n* *\n* * *\n* * * *\n";
For Example
Example write a program that displays the 5×2 matrix using a single output statement
(without using a loop) using Escape Sequences:
cout<<" 1\t 3\t 5\t 7\t 9\n 11\t 13\t 15\t 12\t 19 ";
Example write a program that displays square, the cube of a number in table form using
Escape Sequences:
is one of several means we’ll use to exit a function. When the return statement is used at
the end of main, as shown here, the value 0 indicates that the program has terminated
successfully.
The right brace, }, (line 11) indicates the end of function main. According to the
C++ standard, if program execution reaches the end of main without encountering a return
statement, it’s assumed that the program terminated successfully—exactly as when
the last statement in main is a return statement with the value 0
{
std::cout << "Welcome ";
std::cout << "to C++!\n";
}
return 0;
}
```
Explanation:We have to print the letters using stars. For
that, we have taken the number of lines from the user
and used nested while loop to print the letters. The
outer while loop is used to print the letters beside
each other. We have used two if statements to print the
first letter and last letter. The first letter is printed in
the first line and the last letter is printed in the last
line. To print the first letter, we have used the condition
i == 0 && j == 0 and printed a star. To print the last
letter, we have used the condition i == n - 1 && j == 0
and printed a star. For the remaining letters, we have
printed a space.
Learn more about program :
brainly.com/question/14368396