Thursday, April 15, 2010

A Simple C Program - #include Directives

Now let us move to line 2 for #include

The name of the stdio.h file stands for standard input-output header file. The stdio.h file contains numerous prototypes and macros to perform input or output (I/O) for C programs.

In C, #include forms a preprocessor directive that tells the C preprocessor to look for a file and place the contents of the file in the location where the #include directive indicates. Here, the #include directive does ask the C preprocessor to look for and place stdio.h where the directive is in the C program.

The preprocessor is a program that does some preparations for the C compiler before your code is compiled.

Header Files

The files that are required by the #include directive, like stdio.h, are called header files because the #include directives are almost always placed at the head of C programs. Actually, the extension name of .h does mean "header."

Besides stdio.h, there are more header files, such as stdlib.h, string.h, math.h, and so on.




A Simple C Program - Comment

How do we need to save the C programs?

As we know if you want to save the in excel the extension followed by the name of file ('.xls' for 2003 Excel). By using the same scenario we need to save C programs depending on what application you are using.

The C program is saved as the file name followed by the extension '.c' in the case of simple C compiler application. You can easily observe that the program mentioned in the above image is saved as '02L01.c'.

For DOS application we can save the same program file as '02L01.exe' .

Comments


You notice that this line starts with a combination of a slash and an asterisk, /* ( called opening comment mark), and ends with */ ( called closing comment mark).The C compiler ignores everything between the opening comment mark and closing comment mark while executing the program.

The first line in the program '/* 02L01.c: This is my first C program */' is a comment.

The performance speed of the executable file made from your C program is not affected by the comments inside your C program. You can give as many as comments in the program. It will not increase the size of the executable program file.

Use of comment is FOR - For Our Reference. Comment is like notes that you will get to understand what exactly it is about so that third person can understand it.

/*
This comment does not increase the size of
the executable file (binary code), nor does
it affect the performance speed.
*/

which is equivalent to this:

/* This comment does not increase the size of */
/* the executable file (binary code), nor does */
/* it affect the performance speed. */










Exercise :)

QUIZ for You - What did we learn about C in Introduction of C language I and II?

  1. What are the lowest-level and highest-level languages mentioned in this book?
  2. Can a computer understand a program written in C? What do you need to translate a program written in C into the machine-understandable code (that is, binary code)?
  3. If needed, can a C program be reused in another C program?
  4. Why do we need the ANSI standard for the C language?

Introduction to C language - II

However, there were many changes unofficially made to the C language that were not presented in the book 'The C Programming Language', written by Brian Kernighan and Dennis Ritchie in 1978.

C was on the step to lose its portability. A group of compiler vendors and software developers petitioned the American National Standards Institute (ANSI) to build a standard for the C language in 1983. ANSI approved the application and by the end of 1989, the committee approved the ANSI standard for the C programming language.

Now, all C compilers have the standard library, along with some other compiler-specific functions.
  • C is a general-purpose programming language.
  • C is a high-level language that has the advantages of readability, maintainability, and portability.
  • C is a very efficient language that allows you to get control of computer hardware and peripherals.
  • C is a small language that you can learn easily in a relatively short time.
  • Programs written in C can be reused.
  • Programs written in C must be compiled and translated into machine-readable code before the computer can execute them.
  • C provides many programming languages, such as Perl, C++, and Java, with basic concepts and useful features.
  • The ANSI standard for C is the standard supported by all C compiler vendors to guarantee the portability of C.
  • You can use any C compilers that support the ANSI standard.


Introduction to C language - I

All of us have the mother tongue by default. If you are from North India most probably your mother tongue could be Hindi. If you come to South India where you will find lots of regional languages such as Kannada, Telugu, Malayalam and Tamil etc. Then it is very difficult to converse with the local people who knows their mother tongue how will we converse with them? We usually take the help of global language English in the big cities like Bangalore.

As the same way
computer can only understand the 'on' and 'off' language that is called machine level language. It contains only '0' (zero) and '1' that is called binary language.

C is a programming language. The C language was first developed in 1972 by Dennis Ritchie at AT&T Bell Labs. Ritchie called his newly developed language C simply because there was a B programming language already.

C is one of the high level language.Each high-level language needs a compiler or an interpreter to translate instructions written in the high-level programming language into a machine language that a computer can understand and execute. Different machines may need different compilers or interpreters for the same programming language.


A computer program written in a high-level language, such as C, Java, or Perl, is just a text file, consisting of English-like characters and words. We have to use some special programs, called compilers or interpreters, to translate such a program into a machine-readable code. That is, the text format of all instructions written in a high-level language has to be converted into the binary format. The code obtained after the translation is called binary code. Prior to the translation, a program in text format is called source code.

The smallest unit of the binary code is called a bit (from binary digit), which can have a value of 0 or 1. 8 bits make up one byte, and half a byte (4 bits) is one nibble.