Skip to main content

Posts

Header files in C

header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files.    There are two types of header files: the files that the programmer writes and the files that comes with your compiler.   You request to use a header file in your program by including it with the C preprocessing directive #include , like you have seen inclusion of stdio.h header file, which comes along with your compiler.   Including a header file is equal to copying the content of the header file but we do not do it because it will be error-prone and it is not a good idea to copy the content of a header file in the source files, especially if we have multiple source files in a program. A simple practice in C  is that we keep all the constants, macros, system wide global variables, and function prototypes in the header files and include that header file wherever it is required. Include Syntax Both the user and the system header

Preprocessor Directives

In a C program, all lines that start with # are processed by preprocessor which is a special program invoked by the compiler. In a very basic term, preprocessor takes a C program and produces another C program without any # . There are 4 main types of preprocessor directives: Macros File Inclusion Conditional Compilation Other directives  All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives Sr.No. Directive & Description 1   #define Substitutes a preprocessor macro. 2   #include Inserts a particular header from another file. 3   #undef Undefines a preprocessor macro. 4   #ifdef Returns true if this macro is defined. 5   #ifndef Returns true if this macro is not defined. 6   #if Tests if a compile time condition is true. 7   #else The alt

Introduction to C Programming

C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was first implemented on the DEC PDP-11 computer in 1972. The main features of C language include low-level access to memory, simple set of keywords, and clean style, these features make C language suitable for system programming like operating system or compiler development.Many later languages have borrowed syntax/features directly or indirectly from C language. Like syntax of Java, PHP, JavaScript and many other languages is mainly based on C language. C++ is nearly a superset of C language having object oriented features. Ken Thompson (left) with Dennis Ritchie (right, the inventor of the C programming language) In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard.When C was first written the standard was set by its authors Kernighan and Ritche - hen