C Programming Language Basics www btechsmartclass com Basics
C Programming Language Basics www. btechsmartclass. com
Basics of C Programming? C is a structured programming language. So every instruction in a c program must follow the predefined structure (Syntax). C is also known as Function Oriented Programming Language. So every executable statement must written inside a function. 1
General Structure of a C Program /* Documentation */ Pre-Processing Statements Global Declarations Main method Used defined methods implementation 2
General Structure of a C Program Documentation - It is used to provide brief information of the program. - This part is written using comments. - Generally the documentation part does not executed by compiler & it is optional part. /* Documentation */ Pre-Processing Statements Global Declarations Main method Used defined methods implementation 3
General Structure of a C Program Pre-Processing Statements - It is used to link the header files, define the constants, etc. . . /* Documentation */ Pre-Processing Statements - Every preprocessor statement starts with hash (#) symbol. Main method - Every Preprocessor statement tells to the compiler to perform required pre-processing before the actual compilation. Global Declarations Used defined methods implementation 4
General Structure of a C Program Pre-Processing Statements - Examples #include #define #undef #ifndef #if #else #elif #endif #error #pragma /* Documentation */ Pre-Processing Statements Global Declarations Main method Used defined methods implementation 5
General Structure of a C Program Global Declaration - This part is used to declare the variables which are common for multiple methods. /* Documentation */ Pre-Processing Statements - In this section, we also declare enumeration, structure, unions, userdefined methods etc. . . Main method - It is also optional part. According to our requirement we write this section. Global Declarations Used defined methods implementation 6
General Structure of a C Program Main method - main method is the compulsory part for any c program. /* Documentation */ Pre-Processing Statements - C language is a function oriented programming language, so every c program must have at least one function and that must be main. Global Declarations - Main is a userdefined method which specifies the starting point of the program execution. - Every c program execution starts with main method and ends with main method itself. Main method Used defined methods implementation 7
General Structure of a C Program Userdefined Methods - In this section of the program we write the actual code for the userdefined methods. /* Documentation */ Pre-Processing Statements - Userdefined methods can be implemented either before or after the method. Global Declarations - If it is implemented after the main then it must be declared either inside or before the main method. Main method - If it is implemented before the main the declaration can be ignored. Used defined methods implementation 8
General Structure of a C Program - Example /* Program to print a message Hello World! */ #include<stdio. h> void main() { printf(“Hello World!!!!”); } 9
Rules for Writing C programs Every c program must contain exact one main method Every executable instruction must end with semicolon (; ) All the system defined words (Keywords) must be used in lowercase letters Every open brace ({) must have the respective closing brace (}) The variables must be declared in the declaration section before they are used 10
For more information please visit www. btechsmartclass. com Please do subscribe my channel
- Slides: 12