C programming language was invented by Dennis Ritchie at the Bell Laboratories in 1972. C was invented to write an operating system called UNIX. C programming is considered as the base for other programming languages, that is why it is known as mother language.
Easy to learn
It produces efficient programs
It can handle low-level activities
It can be compiled on a variety of computer platforms
It is widely used in the software development field
Execution of C Program
C is a compiled language. A compiler is a special tool that compiles the program and converts it into the object file which is machine readable. After the compilation process, the linker will combine different object files and creates a single executable file to run the program. Flow given below-
Writing a source Code --->Compiling a source code --->Linking Object-files
(test.c) (test.obj or test.o) (test.exe)
Structure of a C Program
Include header file section
Global declaration section
- C program depends upon some header files for function the definition that is used in the program. Each header file by default is extended with .h. The header file should be included using #
- Some variables that are used in more than one function. These variables are known as global variables. This section must be declared outside of all the functions.
- Every program written in C language must contain main () function. The function main() is a starting point of every C program. The execution of the program always begins with the function main ().
First C Program, open the C console and write the following code:
/* My First C Program */
- Header #include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h .
- int main() The main() function is the entry point of every program in c language.
- The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
- printf() The printf() function is used to print data on the console. The message "Hello World" to be displayed on the screen.
- return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for successful execution and 1 for unsuccessful execution.
How to Compile and run C Program
Type 1- First install gcc compiler and then save code in a file like "first.c"
$ gcc hello.c
Type-2 If you are working in Turbo C++ IDE or in DeV C then,
By menu, click on the compile menu then compile sub menu to compile the c program.
Then click on the run menu then run sub menu to run the c program.
By shortcut, press ctrl+f9 keys compile and run the program directly.
You will see the output on user screen.
You can view the user screen any time by pressing the alt+f5 keys.
Now press Esc to return to the turbo c++ console.