0% found this document useful (0 votes)
2 views

Programing with C & C++ _removed (2)

The document outlines the execution process of a C program, detailing steps from writing source code to generating an executable file. It explains the roles of the compiler and linker, as well as the importance of preprocessor directives in C programming. Additionally, it highlights key syntax rules and provides examples of common preprocessor commands.

Uploaded by

nagarajlaxmi756
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programing with C & C++ _removed (2)

The document outlines the execution process of a C program, detailing steps from writing source code to generating an executable file. It explains the roles of the compiler and linker, as well as the importance of preprocessor directives in C programming. Additionally, it highlights key syntax rules and provides examples of common preprocessor commands.

Uploaded by

nagarajlaxmi756
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Execution Process of a C Program

When we execute a C program it undergoes with the following process…

➢ The file which contains c program instructions in a high-level language is said to be source
code.
➢ Every c program source file is saved with .c extension, for example, Sample.c.

Whenever we press Alt + F9 the source file is submitted to the compiler.
➢ Compiler checks for the errors, if there are any errors, it returns a list of errors, otherwise
generates object code in a file with name Sample.obj and submit it to the linker.
➢ The linker combines the code from specified header file into an object file and generates
executable file as Sample.exe. With this compilation process completes.


Now, we need to run the executable file (Sample.exe). To run a program we press Ctrl
+ F9.
➢ When we press Ctrl + F9 the executable file is submitted to the CPU. Then CPU performs the
task according to the instructions written in that program and place the result into
UserScreen.

Then we press Alt + F5 to open UserScreen and check the result of the program.

Important Points
• C program file (Source file) must save with .c extension.
• The compiler converts complete program at a time from high-level language to low-level
language.
• Input to the compiler is .c file and output from the compiler is .exe file, but it also
generates .obj file in this process.
• The compiler converts the file only if there are no errors in the source code.
• CPU places the result in User Screen window.
Overall Process
• Type the program in C editor and save with .c extension (Press F2 to save).
• Press Alt + F9 to compile the program.
• If there are errors, correct the errors and recompile the program.
• If there are no errors, then press Ctrl + F9 to execute/run the program.
• Press Alt + F5 to open User Screen and check the result.
Some basic syntax rule for C program

• C is a case sensitive language so all C instructions must be


written in lower case letter.
• All C statement must end with a semicolon.
• Whitespace is used in C to describe blanks and tabs.
• Whitespace is required between keywords and identifiers.
Pre-processors in “ C ”
➢ The C Preprocessor is just a text substitution tool and it instructs the compiler
to do required pre-processing before the actual compilation.
➢ All preprocessor commands begin with a hash symbol (#).
➢ It must be the first nonblank character, and for readability, a preprocessor
directive should begin in the first column.
➢ The following section lists down all the important preprocessor directives −

Sr.No. Directive & Description

1
#define
Substitutes a preprocessor macro.

2
#include
Inserts a particular header from another
file.

3
#undef
Undefines a preprocessor macro.

4
#ifdef
Returns true if this macro is defined.

5
#ifndef
Returns true if this macro is not defined.

6
#if
Tests if a compile time condition is true.

7
#else
The alternative for #if.

8
#elif
#else and #if in one statement.
9
#endif
Ends preprocessor conditional.

10
#error
Prints error message on stderr.

11
#pragma
Issues special commands to the compiler,
using a standardized method.

Preprocessors Examples
Analyze the following examples to understand various directives.
#define MAX_ARRAY_LENGTH 20
This directive tells the CPP to replace instances of MAX_ARRAY_LENGTH with 20.
Use #define for constants to increase readability.
#include <stdio.h>
#include "myheader.h"

These directives tell the CPP to get stdio.h from System Libraries and add the text
to the current source file. The next line tells CPP to get myheader.h from the local
directory and add the content to the current source file.
#undef FILE_SIZE
#define FILE_SIZE 42

It tells the CPP to undefine existing FILE_SIZE and define it as 42.


#ifndef MESSAGE
#define MESSAGE "You wish!"
#endif

It tells the CPP to define MESSAGE only if MESSAGE isn't already defined.
#ifdef DEBUG
/* Your debugging statements here */
#endif

It tells the CPP to process the statements enclosed if DEBUG is defined. This is useful
if you pass the -DDEBUG flag to the gcc compiler at the time of compilation. This will
define DEBUG, so you can turn debugging on and off on the fly during compilation.

You might also like