#include Directive and Header Files in C Programming

Submitted by tushar pramanick on Mon, 02/25/2013 - 12:33

The #include Directive
Let's now move to line 2 in the C program of Listing 2.1:


#include <stdio.h>

You see that this line starts with a pound sign, #, which is followed by include. 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.

The preprocessor is a program that does some preparations for the C compiler before your code is compiled. More details about the C preprocessor are discussed in Hour 23, "The C Preprocessor."

Also in this line, you see that <stdio.h> follows #include. You may guess that the file the #include directive asks for is something called stdio.h. You are exactly right! 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 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. You'll see more program I/O in Hour 5, "Reading from and Writing to Standard I/O."

 

NOTE

The C programming language distinguishes between lowercase and uppercase characters. In other words, C is a case-sensitive language. For instance, stdio.h and STDIO.H are different filenames in C. Likewise, main() and Main() are two different function names.

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. Appendix A, "ANSI Standard Header Files," gives a list of all the ANSI standard header files.

 

Angle Brackets (< >) and Double Quotes (" ")
In the second line of Listing 2.1, there are two angle brackets, < and >, that are used to surround stdio.h. You may be wondering what the angle brackets do. In C, the angle brackets ask the C preprocessor to look for a header file in a directory other than the current one.

For instance, the current directory containing the 02L01.C file is called C:\code on my computer. Therefore, the angle brackets around <stdio.h> tell the C preprocessor to look for stdio.h in a directory other than C:\code.

If you want to let the C preprocessor look into the current directory first for a header file before it starts to look elsewhere, you can use double quotes to surround the name of the header file. For instance, when the C preprocessor sees "stdio.h", it looks in the current directory, which is C:\code on my machine, first before it goes elsewhere for the stdio.h header file.

Normally, the header files are saved in a subdirectory called include. For instance, I might install a Microsoft C compiler in the directory MSVC on my hard drive, which is labeled as the C drive. Then the path to access the header files becomes C:\MSVC\include.

 

 

Comments

Related Items

C প্রোগ্রাম এর ডেটা টাইপ এবং নামকরণ করার পদ্ধতি

ক্লাস 4: C ল্যাঙ্গুয়েজ এর ডেটা টাইপ এবং নেম

CLASS 4: Data Types and Names in C

C প্রোগ্রাম এর প্রয়োজনীয় উপকরন

C Programs এর প্রয়োজনীয় উপকরন

এই অধ্যায়ে আমরা শিখবো সি প্রোগ্রামিং এর জন্য কিছু প্রয়োজনীয় জিনিস । যেমন

সহজ সরল প্রথম C প্রোগ্রাম টি লিখতে শিখুন

আমরা জানি C একটি উচ্চ-স্তরের প্রোগ্রামিং ভাষা এবং C প্রোগ্রামগুলি বাইনারি কোডে অনুবাদ করতে C কম্পাইলার (Compiler) দরকার হয় । বাইনারি কোড কম্পিউটার বুঝতে পারে এবং এক্সিকিউট করতে পারে। C প্রোগ্রাম লিখতে যে বেসিক জিনিসগুলি জানতে হবে

C প্রোগ্রামিং কিভাবে শুরু করবে ?

C একটি প্রোগ্রামিং ল্যাঙ্গুয়েজ । C ল্যাঙ্গুয়েজ প্রথম তৈরি করেন ডেনিস রিচি (Dennis Ritchie) 1972 সালে AT&T Bell ল্যাবে । ডেনিস রিচি এর নাম দেন ল্যাঙ্গুয়েজ C । কারন এর আগে B বলে আগে থেকেই আর একটি প্ররগ্রামিং ল্যাঙ্গুয়েজ ছিল।

C programming in Bengali

C প্রোগ্রামিং ল্যাঙ্গুয়েজ শেখার জন্য আগে থেকে কোনও প্রোগ্রামিং ল্যাঙ্গুয়েজ জানার প্রয়োজন নেই, যদিও কম্পিউটারের সম্পর্কে কিছু জ্ঞান থাকার দরকার । C একটি শক্তিশালী সাধারণ উদ্দেশ্যে ব্যাবহৃত প্রোগ্রামিং ল্যাঙ্গুয়েজ। C প্রোগ্রামিং ল্যাঙ্গুয়েজ দিয়ে অপারেটিং সিস্টেম, ডাটাবেস, ..