Describe the structure of C program (2nd day)
This is the second day of our 7 days C tutorial. If you have not come across the 1st day lesson, then you can follow Getting started with C and Embedded C programming: Study C in 7 days . Now C language has its own structure to write a program, that is there are particular rules for writing codes in C. These rules are called Syntax Rules. All the codes written in a C program is based on these syntax rules. We can classify a C program as many sections, the different sections in a C program are followed, this is a general way of representation.Documentation section
Name of program, name of programmer, date etc. are included in the documentation part. These are non executable. To start and stop documentation we are using /* and */ command. For example,In Embedded C we are using ‘//’ for commenting like,
Linkage section
In this section we provide instructions for linking different functions from the system library to the compiler. This section is also known as Pre Processing stage, because this will run before the main() at the time of execution. The file name starts with ‘#’ symbol. For example, #includeGlobal variable declaration section
The variables declared in this section are accessible from any program. Any function other than main() can use this variables. For example,Here the variables a, b, c are global variables. The main() and function1() can also access these variables.
Main() function
We can group some codes together, these grouped program codes are called functions. Main() is the entry function of any program. It indicates the starting of program. There are two sections in main function(),1.Declaration part
In this part we declare all the variable used in the main() program. The variables cannot be accessible from outside of main() function. For example
Different operations are included in this part. For example
We can write main() function once in a program, so main() works as a built in function. The user combines all other functions in main() section.
User defined functions
The functions defined by user and called from main() function are known as user defined functions. All the user defined functions are written after the main() function. In Embedded C, user defined functions are written before main().Comments and Remarks
/* and */ are used anywhere in the program to indicate some information to another programmer, this will help the programmer in the Debugging process also, another user can easily understand the logic. For exampleBut in Embedded C we use '//' for commenting. Like,
So that's all for the 2nd day tutorial. Check out other Study C in 7 days tutorials:
- Introduction to C programming Day 1
- Structure of a C program (This tutorial)
- Constants and variables in C Day 3
- Data types, Operators and operations in C program Day 4
- Input Output operation and control statements in C programming Day 5
- Loops or iterative statements in C program Day 6
- Write execute your first C program Day 7
Ads
0 comments:
Post a Comment