Introduction to 'C' programming language for SEE and NEB
Facts about C
- C was invented to write an operating system called UNIX.
- C is a successor of B language which was introduced around the early 1970s.
- The UNIX OS was completely developed in C.
- ‘C’
is the most widely used and popular System Programming Language in today’s
programming field.
- Most of the software has been developed by using ‘C’
- Today's most popular Linux OS and RDBMS MySQL have been written in C.
- It is simple to learn because it has a small set of commands.
- It is a structured programming language.
- Programs written in C language is machine independent.
- Modular programming is possible.
- It is a bridge between high-level and low-level language.
- It is much faster than other languages.
- It supports a different set of data types and data declarations.
- It provides several built-in functions to perform several tasks.
- It is a powerful high-level language that allows developing different types of commercial as well as hardware-related programming.
- The programs written in ‘C’ are independent.
Advantages and disadvantages of C language:
Advantages:
- It is machine independent.
- It is portable programming language.
- It is mother of all modern programming language.
- Its compiler is easily available.
- It has the capability of both high level and low level programming language.
- It is fast for executing.
Disadvantages:
- There is no runtime checking.
- On large program, it is difficult to fix errors.
- Object oriented programming is not possible.
- It is complex and hard for the beginners.
Before
understanding the structure of 'C' program you must know the following points:
- 'C' is a case sensitive language, it means all the keywords must be written in lowercase.
- Keywords can't be used as variable or function name.
- Every instruction should be end with (;) sign.
- Preprocessor directives should be there in the beginning.
- Function main() is must for a program.
While
writing a program in 'C' we have to follow the following steps:
i. Define preprocessor directives (include header files
according to prototype functions, standard I/O library function to be used)
ii. Open function main ( ).
iii. Assign data type and variables.
iv. Define the body of the function.
v. End the function main ( ).
Example:
1: /* Example of 'C'
programming*/
2: #include<stdio.h>
3: void main()
4: {
5: int a=10, b=15, c;
6: printf("Welcome to 'C'
world \n");
7: c=a+b;
8: printf("The sum of %d and
%d is %d",a,b,c);
9: }
Note: Don't use colon sing and line
number while writing the program in C.
In above example:
First Line: /*
Example of 'C' programming*/
It is a comment and
non-executable.
Second Line: #include<stdio.h>
It is a preprocessor directive.
The preprocessor process the 'C' program before the compiler. stdio.h is a
header file which consists of standard I/O functions. More than one header file
can be used in a program.
Third Line:
void main()
It indicated the beginning of the
program. The compilation of the ‘C’ program starts from main () function.
Fourth Line: {
This symbol indicates the
beginning of main () function.
Fifth Line: int a=10, b=15, c;
It is used for declaration of
variables and data types.
Sixth, Seventh and Eighth Line:
These lines are the body of the
programs.
Ninth Line: }
It indicates the end of main ()
function.
To Run the program:
1. Press ALT+F9
to compile the program.
2. Press CTRL
+ F9 to RUN the program.
3. Press ALT
+ F5 to View the output.
No comments:
Post a Comment