Understanding Basic
Programming Structure of C
C Preprocessors
• As the name suggests Preprocessors are programs that process our source
code before compilation.
• In C, all lines that begin with # are directives for the
preprocessor, which means that all these directives will be
processed before the program is actually compiled. The
#include directive includes the contents of a file during
compilation. In this case, the file stdio.h is added in the
source program before the actual compilation begins.
• stdio.h
is a header file that comes with the C compiler and contains
information about input and output functions, e.g., printf()
Header files
A header file is a file containing C declarations and macro
definitions to be shared among the source files, compiler,
preprocessor, C library, and other header files.
In C, the usual convention is to give header files names
that end with .h.
•
The ISO C standard library consists of 24 header
files which can be included into a programmer’s project with
a single directive. Each header file contains one or more
function declarations, data type definitions, and macros.
• In C, all lines that begin with # are directives for the
preprocessor, which means that all these directives will be
processed before the program is actually compiled. The
#include directive includes the contents of a file during
compilation. In this case, the file stdio.h is added in the
source program before the actual compilation begins.
• stdio.h
is a header file that comes with the C compiler and contains
information about input and output functions, e.g., printf()
Header files
A header file is a file containing C declarations and macro
definitions to be shared among the source files, compiler,
preprocessor, C library, and other header files.
In C, the usual convention is to give header files names
that end with .h.
•
The ISO C standard library consists of 24 header
files which can be included into a programmer’s project with
a single directive. Each header file contains one or more
function declarations, data type definitions, and macros.
Some of C Header files:
• stdio.h – Standard Input Output. Defines core input and output functions.
stdio.h is a header file which has the necessary information to include the
input/output related functions in our program. Example printf, scanf etc.
• conio.h –console input/output. Some of its most commonly used
functions are clrscr, getch, etc. They can be used to clear screen, change
color of text and background, eyc
• string.h – Defines string handling functions
• math.h – Defines common mathematical functions
Difference between “int main()” and “int main(void)”
• int main() can be called with any number of arguments
• int main(void) can only be called without any argument.
• Although it doesn’t make any difference most of the times, using “int
main(void)” is a recommended practice in C
• Preprocessor programs provide preprocessors directives which tell
the compiler to preprocess the source code before compiling.
• All of these preprocessor directives begin with a ‘#’ (hash) symbol.
The ‘#’ symbol indicates that, whatever statement starts with #, is
going to the preprocessor program, and preprocessor program will
execute this statement.
• The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process.
• In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do
required pre-processing before the actual compilation.
• #define
• Substitutes a preprocessor macro.
• #include
• Inserts a particular header from another file.
• #include <stdio.h>
• #include "myheader.h“
• #define MAX_ARRAY_LENGTH 20
• 1) When we use include directive, the contents of included header file
(after preprocessing) are copied to the current file.
• 2) When we use define for a constant, the preprocessor produces a C
program where the defined constant is searched and matching tokens are
replaced with the given expression. For example in the following program
max is defined as 100.
#include <stdio.h>
#define max 100
int main()
{
printf("max is %d", max);
return 0;
}
Linker
• A linker is a program in a system, also known as a link editor and
binder, which combines object modules into a single object file.
• Generally, it is a program that performs the process of linking; it takes
one or multiple object files, which are generated by compiler. And,
then combines these files into an executable files.
• Modules are called for the different pieces of code, which are written
in programming languages.
• Linking is a process that helps to gather and maintain a different piece
of code into an executable file or single file.
• The linker is a program in a system, also known as link editor and
binder, which combines object modules into a single object file.
• The loader is a special program that loads the executable module of a
program that is generated by the linker and prepares this code for
execution by a computer.
Adding 2 Numbers
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx
U get to UnderstandingBasicStructureC.pptx

U get to UnderstandingBasicStructureC.pptx

  • 1.
  • 8.
    C Preprocessors • Asthe name suggests Preprocessors are programs that process our source code before compilation.
  • 9.
    • In C,all lines that begin with # are directives for the preprocessor, which means that all these directives will be processed before the program is actually compiled. The #include directive includes the contents of a file during compilation. In this case, the file stdio.h is added in the source program before the actual compilation begins. • stdio.h is a header file that comes with the C compiler and contains information about input and output functions, e.g., printf()
  • 10.
    Header files A headerfile is a file containing C declarations and macro definitions to be shared among the source files, compiler, preprocessor, C library, and other header files. In C, the usual convention is to give header files names that end with .h. • The ISO C standard library consists of 24 header files which can be included into a programmer’s project with a single directive. Each header file contains one or more function declarations, data type definitions, and macros.
  • 12.
    • In C,all lines that begin with # are directives for the preprocessor, which means that all these directives will be processed before the program is actually compiled. The #include directive includes the contents of a file during compilation. In this case, the file stdio.h is added in the source program before the actual compilation begins. • stdio.h is a header file that comes with the C compiler and contains information about input and output functions, e.g., printf()
  • 13.
    Header files A headerfile is a file containing C declarations and macro definitions to be shared among the source files, compiler, preprocessor, C library, and other header files. In C, the usual convention is to give header files names that end with .h. • The ISO C standard library consists of 24 header files which can be included into a programmer’s project with a single directive. Each header file contains one or more function declarations, data type definitions, and macros.
  • 14.
    Some of CHeader files: • stdio.h – Standard Input Output. Defines core input and output functions. stdio.h is a header file which has the necessary information to include the input/output related functions in our program. Example printf, scanf etc. • conio.h –console input/output. Some of its most commonly used functions are clrscr, getch, etc. They can be used to clear screen, change color of text and background, eyc • string.h – Defines string handling functions • math.h – Defines common mathematical functions
  • 15.
    Difference between “intmain()” and “int main(void)”
  • 16.
    • int main()can be called with any number of arguments • int main(void) can only be called without any argument. • Although it doesn’t make any difference most of the times, using “int main(void)” is a recommended practice in C
  • 17.
    • Preprocessor programsprovide preprocessors directives which tell the compiler to preprocess the source code before compiling. • All of these preprocessor directives begin with a ‘#’ (hash) symbol. The ‘#’ symbol indicates that, whatever statement starts with #, is going to the preprocessor program, and preprocessor program will execute this statement.
  • 18.
    • The CPreprocessor is not a part of the compiler, but is a separate step in the compilation process. • In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. • #define • Substitutes a preprocessor macro. • #include • Inserts a particular header from another file.
  • 19.
    • #include <stdio.h> •#include "myheader.h“ • #define MAX_ARRAY_LENGTH 20
  • 20.
    • 1) Whenwe use include directive, the contents of included header file (after preprocessing) are copied to the current file. • 2) When we use define for a constant, the preprocessor produces a C program where the defined constant is searched and matching tokens are replaced with the given expression. For example in the following program max is defined as 100.
  • 21.
    #include <stdio.h> #define max100 int main() { printf("max is %d", max); return 0; }
  • 22.
    Linker • A linkeris a program in a system, also known as a link editor and binder, which combines object modules into a single object file. • Generally, it is a program that performs the process of linking; it takes one or multiple object files, which are generated by compiler. And, then combines these files into an executable files. • Modules are called for the different pieces of code, which are written in programming languages. • Linking is a process that helps to gather and maintain a different piece of code into an executable file or single file.
  • 24.
    • The linkeris a program in a system, also known as link editor and binder, which combines object modules into a single object file. • The loader is a special program that loads the executable module of a program that is generated by the linker and prepares this code for execution by a computer.
  • 27.