C programming structure is based on the problem. But there are several structural elements and syntax that are constant in all problems. You can also view our articles on introduction to C programming here. Following are 3 types of programming used.
In structured programming, the user can divide a code into several smaller programs which are called functions. This type of programming follows a “top-down” approach which means that the program execution starts from the first line of code and keeps on continuing till the last line. Ex: Pascal, C programming, etc.
In Object-oriented programming, as the name suggests, the user can use a new property called object which can be used to call a function multiple times. This ability gives the coder an option of reusability, which is an advantage of Object-oriented programming over Structured Programming. This programming follows the “Bottom-up” approach, which means that the program starts from a base element and follows the function and object calls. Ex: Java, C++, etc.
As the name indicates, this type of programming language does not follow any particular structure. They are executed sequentially and do not jump from any line. Ex: COBOL, BASIC, etc.
C programming follows Structured Programming.
Following is an example of a body of c program.
void main ( )
data_type name;//(ex: int a, char b)
scanf(“ “);//input function
printf(“ “);//output function
In C programming, the first lines contain the headers of a program. The header files contain already defined functions that can be used by calling them. Ex: stdio.h = is a header file that allows the scanner and printer function to scanf() and print(). math.h = provides functions like sqrt(), pow(), etc, which gives mathematical related function.
Another thing that is used with functions is return types, which depend on what type of value the function is returning.
Ex void = do not return a value
int = return integer value
char = return character value
A variable is declared as follows
Ex = int Integer1;
Following are rules required for data name:
- The name should start with either alphabet (a-z or A-Z) or underscore ( _ ).
- Name can include alphabets, numbers, and underscore.
- Name cannot have commas or spaces.
- No special characters are allowed while naming variables.
- Names are case-sensitive i.e. name, Name, nAme, naMe, etc are different.