The perfect place for easy learning...

C Programming Language


Topics List

Place your ad here

C Program Basics

C is a structured programming language. Every c program and its statements must be in a particular structure. Every c program has the following general structure...

general structure of c,c program general structure,c general structure

Line 1: Comments - They are ignored by the compiler

This section is used to provide a small description of the program. The comment lines are simply ignored by the compiler, that means they are not executed. In C, there are two types of comments.

  1. Single Line Comments: Single line comment begins with // symbol. We can write any number of single line comments.
  2. Multiple Lines Comments: Multiple lines comment begins with /* symbol and ends with */. We can write any number of multiple lines comments in a program.

In a C program, the comment lines are optional. Based on the requirement, we write comments. All the comment lines in a C program just provide the guidelines to understand the program and its code.

Line 2: Preprocessing Commands

Preprocessing commands are used to include header files and to define constants. We use the #include statement to include the header file into our program. We use a #define statement to define a constant. The preprocessing statements are used according to the requirements. If we don't need any header file, then no need to write #include statement. If we don't need any constant, then no need to write a #define statement.

Line 3: Global Declaration

The global declaration is used to define the global variables, which are common for all the functions after its declaration. We also use the global declaration to declare functions. This global declaration is used based on the requirement.

Line 4: int main()

Every C program must write this statement. This statement (main) specifies the starting point of the C program execution. Here, main is a user-defined method which tells the compiler that this is the starting point of the program execution. Here, int is a data type of a value that is going to return to the Operating System after completing the main method execution. If we don't want to return any value, we can use it as void.

Line 5: Open Brace ( { )

The open brace indicates the beginning of the block which belongs to the main method. In C program, every block begins with a '{' symbol.

Line 6: Local Declaration

In this section, we declare the variables and functions that are local to the function or block in which they are declared. The variables which are declared in this section are valid only within the function or block in which they are declared.

Line 7: Executable statements

In this section, we write the statements which perform tasks like reading data, displaying the result, calculations, etc., All the statements in this section are written according to the requirements.

Line 9: Closing Brace ( } )

The close brace indicates the end of the block which belongs to the main method. In C program every block ends with a '}' symbol.

Line 10, 11, 12, ...: User-defined function()

This is the place where we implement the user-defined functions. The user-defined function implementation can also be performed before the main method. In this case, the user-defined function need not be declared. Directly it can be implemented, but it must be before the main method. In a program, we can define as many user-defined functions as we want. Every user-defined function needs a function call to execute its statements.

General rules for any C program

  1. Every executable statement must end with a semicolon symbol (;).
  2. Every C program must contain exactly one main method (Starting point of the program execution).
  3. All the system-defined words (keywords) must be used in lowercase letters.
  4. Keywords can not be used as user-defined names(identifiers).
  5. For every open brace ({), there must be respective closing brace (}).
  6. Every variable must be declared before it is used.

Place your ad here
Place your ad here