Computer Science, asked by surajshakya9696, 8 months ago

after successful compilation of a program , which option should be selected to run a program​

Answers

Answered by manasgupta2506
1

Answer:

full information

Explanation:

There are three steps in executing a c++ program: Compiling, Linking and Running the program. The c++ programs have to be typed in a compiler. All the programs discussed in the book will be compiled on turbo c++ compiler. The turbo c++ compiler comes with an editor to type and edit c++ program.

After typing the program the file is saved with an extension .cpp. This is known as source code. The

source code has to be converted to an object code which is understandable by the machine. This

process is known as compiling the program. You can compile your program by selecting compile from

compile menu or press Alt+f9. After compiling a file with the same name as source code file but with

extension .obj. is created.

Second step is linking the program which creates an executable file .exe (filename same as

source code) after linking the object code and the library files (cs.lib) required for the program. In a

simple program, linking process may involve one object file and one library file. However in a project,

there may be several smaller programs. The object codes of these programs and the library files are

linked to create a single executable file. Third and the last step is running the executable file where the

statements in the program will be executed one by one.

When you execute the program, the compiler displays the output of the program and comes

back to the program editor. To view the output and wait for user to press any key to return to the

editor, type getch() as the last statement in the program. Getch() is an inbuilt predefined library

function which inputs a character from the user through standard input. However you should include

another header file named conio.h to use this function. Conio.h contains the necessary declarations for

using this function. The include statement will be similar to iostream.h.

Compiling and Linking

During compilation, if there are any errors that will be listing by the compiler. The errors may be any

one of the following

1.Syntax error

This error occurs due to mistake in writing the syntax of a c++ statement or wrong use of

reserved words, improper variable names, using variables without declaration etc. Examples are :

missing semi colon or paranthesis, type integer for int datatype etc. Appropriate error message and

the statement number will be displayed. You can see the statement and make correction to the

program file, save and recompile it.

2. Logical error

This error occurs due to the flaw in the logic. This will not be identified by the compiler.

However it can be traced using the debug tool in the editor. First identify the variable which you

suspect creating the error and add them to watch list by selecting Debug ->Watches->Add watch.

Write the variable name in the watch expression. After adding all the variables required to the watch

list, go to the statement from where you want to observe. If you are not sure, you can go to the first

statement of the program. Then select Debug ->Toggle Breakpoint (or press ctrl + f8). A red line will

appear on the statement. Then Run the program by selecting Ctrl + f9 or Run option from run menu.

The execution will halt at the statement where you had added the breakpoint. The watch variables and

their values at that point of time will be displayed in the bottom in the watch window. Press F8 to

execute the next statement till you reach the end of the program. In this way you can watch closely

the values in the watch variables after execution of each and every statement in the program. If you

want to exit before execution of the last statement press Ctrl + Break. To remove the breakpoint in the

program go to the statement where you have added breakpoint select Debug ->Toggle Breakpoint (or

press ctrl + f8).Select Debug -> watch ->remove watches to remove the variables in the watch list. This

tool helps in knowing the values taken by the variable at each and every step. You can compare the

expected value with the actual value to identify the error.

3. Linker error

This error occur when the files during linking are missing or mispelt

4. Runtime error

This error occurs if the program encounters division by zero, accessing a null pointer etc during

execution of the program.

Similar questions