C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » C programming language

Introduction & getting started with C language

Why learn C Language?

It’s first question which comes in mind, when you start to learn C language. Why we are learning C and what are the benefits to learn C, why it is necessary to learn. Well, here are some points which may help you to clear your confusions about to learn C language.

  • C language is a middle level language; it supports the features of low level and high level languages.
  • C language is helpful to develop low level application that interacts with system hardware such as device drivers, firmware’s, operating system etc and high level applications (user level).
  • C language programs are portable; you can easily run on different PC.
  • C language supports modular programming style, by using this style you can divide your program (problem) into small pieces and integrating them, you can build a complete program.
  • C language has only 32 keywords, so it is very easy to learn, understand and use.
  • C language follows top to down programming approach.

Getting started with “First C Program”

It is good approach to learn any programming language, to write first program. We all know the program is to print “Hello world!” Here we are going to learn how to write a program in C language.

/* My first program */
#include <stdio.h>
int main()
{
	printf("Hello World! \n");
	return 0;
}

/* My first program */

Comments can be inserted into C programs by bracketing text with the /* and*/ delimiters. Comments are useful for many reasons. Basically comments are used for internal documentation of the program, internal documentations are very necessary as they are useful for the programs to understand what’s logics are using in the program and how program works.

#include <stdio.h>

This is header files inclusion section; here, we include header files, This section allows you to use functions that are declared in it. For example we are using printf in this program and stdio.h header file contains it’s declaration. Here, we include all those header files which are required to access their library functions.

int main()

main() is a system declared thread, which are defined by the programmer i.e. you can write your code with in it that you want to program. It is the first function that tells to the compiler to execute your program. Program’s execution starts from here.

int is a return type of the function, which returns an integer value after the execution of the program to the operating system.

{..}

{ and }, these two braces are the starting and ending braces of the main segment, these defines the block of particular function.

printf("Hello World! \n");

printf is a library function, that is used to print text as well as values of the variables to the standard output device. It is declared in staio.h.

return 0;

Since main has int return type, so we must use return statement at the end of the main’s code, just before the end brace (}).