KEMBAR78
C Programming Lecture 2 - Structure of a C Program.pptx
Programming in C
Core Course
Course Instructor
Dr. Murali Malijeddi
Professor
Dept. of ECE, CUTM AP
Developing a Software
Translators
Translators
Characteristics of C
•C Language is a middle level language.
•It has the simplicity of a high level language
•It has the power of low level language.
Characteristics of C
• C is small language
• Consisting of only 32 English words known as keywords
(if, else, for, break etc.)
• The power of C is augmented by the library functions provided
with it.
• Moreover, the language is extendible
• It allows the users to add their own library functions to the library.
• The programs written in C are portable
Structure of a C Program
•C program is a collection of one or more - functions.
•Every function is a collection of statements
•A function performs some specific task.
•The general structure of C program is:
Structure of a C Program
Structure of a C Program
•Comments can be placed anywhere in a program
•Comments are enclosed between the delimiters
/* */
•E.g., /* Blah Blah… blah... */
•Comments are generally used for documentation purposes.
Structure of a C Program
• Preprocessor directives are processed through Preprocessor
before the C source code passes through Compiler.
• The most commonly used preprocessor directives are
#include and #define
• #include is used for including header files.
• #define is used to define symbolic constants and macros.
• Note:
• Preprocessor directives begin with #.
• Only white-space and comments may appear a Preprocessor directives in a program.
Structure of a C Program
Structure of a C Program
• Every C program has one or more functions.
• If a program has only one function then it must be main()
• Execution of every C program starts with main() function.
• main() function has two parts:
• declaration of local variables
• and statements
•
Structure of a C Program
•The scope of the local variable is local to that function only.
•Statements in the main function are executed one by one.
•Other functions are the user-defined functions, which also
have local variables and C statements.
•Other functions can be defined before or after main().
Structure of a C Program
•It may be possible that some variables have to be used in
many functions, so it is necessary to declare them globally.
•These variables are called global variables.
Environment For C
•The steps for the execution of C program are as-
1. Program creation
2. Program compilation
3. Program execution
Environment For C
•The C programs are written in mostly two environments:
1. UNIX Environment
2. Windows (MS-DOS) Environment
•MS-DOS environment creation, compilation and execution
can be done using command line or IDE (integrated
Development Environment).
Unix Environment
•Generally a command line C compiler is provided with the
UNIX operating system.
•This compiler is named gcc or cc,
Unix Environment - Program creation
•In UNIX environment, file can be created with "vi editor”
•$ vi filename.c
•Here $ is the Unix prompt.
•The file can be saved by pressing
• ESC and SHIFT+zz
Or
• ESC and :wq + Enter
Unix Environment - Program compilation
• Two different ways are there:
Method - 1)
• After creation of C program, it can be compiled as:
$ gcc filename.c
• Program has mathematical function then it is compiled as:
$ gcc filename.c -lm
• After compilation, the executable code is stored in the file 'a.out'.
•
Unix Environment - Program compilation
Method - 2)
$ gcc filename.c -o ProgramName
•Program has mathematical function then
$ gcc filename.c -lm -o ProgramName
•After compilation, the executable code is stored in the file
'ProgramName'.
Unix Environment - Program execution
•After the compilation of program, it can be executed as:
$ ./a.out
Or
$ ./ProgramName
C Programming Lecture 2 - Structure of a C Program.pptx

C Programming Lecture 2 - Structure of a C Program.pptx

  • 1.
    Programming in C CoreCourse Course Instructor Dr. Murali Malijeddi Professor Dept. of ECE, CUTM AP
  • 2.
  • 3.
  • 4.
  • 5.
    Characteristics of C •CLanguage is a middle level language. •It has the simplicity of a high level language •It has the power of low level language.
  • 6.
    Characteristics of C •C is small language • Consisting of only 32 English words known as keywords (if, else, for, break etc.) • The power of C is augmented by the library functions provided with it. • Moreover, the language is extendible • It allows the users to add their own library functions to the library. • The programs written in C are portable
  • 7.
    Structure of aC Program •C program is a collection of one or more - functions. •Every function is a collection of statements •A function performs some specific task. •The general structure of C program is:
  • 8.
    Structure of aC Program
  • 9.
    Structure of aC Program •Comments can be placed anywhere in a program •Comments are enclosed between the delimiters /* */ •E.g., /* Blah Blah… blah... */ •Comments are generally used for documentation purposes.
  • 10.
    Structure of aC Program • Preprocessor directives are processed through Preprocessor before the C source code passes through Compiler. • The most commonly used preprocessor directives are #include and #define • #include is used for including header files. • #define is used to define symbolic constants and macros. • Note: • Preprocessor directives begin with #. • Only white-space and comments may appear a Preprocessor directives in a program.
  • 11.
    Structure of aC Program
  • 12.
    Structure of aC Program • Every C program has one or more functions. • If a program has only one function then it must be main() • Execution of every C program starts with main() function. • main() function has two parts: • declaration of local variables • and statements •
  • 13.
    Structure of aC Program •The scope of the local variable is local to that function only. •Statements in the main function are executed one by one. •Other functions are the user-defined functions, which also have local variables and C statements. •Other functions can be defined before or after main().
  • 14.
    Structure of aC Program •It may be possible that some variables have to be used in many functions, so it is necessary to declare them globally. •These variables are called global variables.
  • 15.
    Environment For C •Thesteps for the execution of C program are as- 1. Program creation 2. Program compilation 3. Program execution
  • 16.
    Environment For C •TheC programs are written in mostly two environments: 1. UNIX Environment 2. Windows (MS-DOS) Environment •MS-DOS environment creation, compilation and execution can be done using command line or IDE (integrated Development Environment).
  • 17.
    Unix Environment •Generally acommand line C compiler is provided with the UNIX operating system. •This compiler is named gcc or cc,
  • 18.
    Unix Environment -Program creation •In UNIX environment, file can be created with "vi editor” •$ vi filename.c •Here $ is the Unix prompt. •The file can be saved by pressing • ESC and SHIFT+zz Or • ESC and :wq + Enter
  • 19.
    Unix Environment -Program compilation • Two different ways are there: Method - 1) • After creation of C program, it can be compiled as: $ gcc filename.c • Program has mathematical function then it is compiled as: $ gcc filename.c -lm • After compilation, the executable code is stored in the file 'a.out'. •
  • 20.
    Unix Environment -Program compilation Method - 2) $ gcc filename.c -o ProgramName •Program has mathematical function then $ gcc filename.c -lm -o ProgramName •After compilation, the executable code is stored in the file 'ProgramName'.
  • 21.
    Unix Environment -Program execution •After the compilation of program, it can be executed as: $ ./a.out Or $ ./ProgramName