Overview
General purpose programming language
In the past, languages were used for specific purposes, such as FORTRAN for calculations, COBOL for business-oriented applications.
C is a general usage imperative programming language.
The History of C
- It all started with a research paper on a new programming language C by Dennis Ritchie and Ken Thompson
- C was derived from language B (Ken Thompson) which originated from BCPL (Basic Combined Programming Language @Martin Richards)
- By 1970, C evolved into now 'Traditional C'
- Due to the rapid expansion of C, many hardware-depend variants came into the picture, which were similar to Traditional C but incompatible, so a committee was formed for its standardisation, ANSI (American Standard Standards Institute)
What does it provides?
- Very fast (almost similar to assembly)
- Cross-platform code (mostly)
- Highly flexible viz. has a lot of libraries
- Takes advantage of capabilities of the current compilers
- Provides low level access to memory and lets us efficiently manipulate it, but there is a trade-off b/w freedom and responsibility and it allows C to be used for both system programming and application programming.
- Portability: Cross-platform support for the C-code due to the availability of powerful compilers
>The Standard C
- Standards version of C were created then (C/89, C99 and C11)
- Programs written in C written w/o any hardware-dependent assumptions will run correctly on any platform if compiled by a Standard C compiler
<aside>
👉 C89
</aside>
- aka ANSI C
- Supported by current C compilers
- It's the base of all the revised standards
<aside>
👉 C99
</aside>
- Revised standard of C89 that expands its capabilities such as variable length arrays, single line comments etc,
true
/ false
of stdbool.h
- Not widely adopted and not a lot of compilers support it
<aside>
👉 C11
</aside>
- The current standard
- Support by current C compilers
>Working With Larger Programs
- Before even starting to write code, we should decide how to break down the program into multiple modules. Writing the entire code in a single file and then later debugging and trying to break it down will leak to failure and rewriting the code from scratch.
- We should break down a large codebase into smaller modules, and all type of similar code should be in a module.
- We should use an IDE when dealing with a large codebase.
- We should leverage these techniques of
typedef
and #define
, to do just like MS did with Hardware Abstraction Layer, and write very machine independent code. When a machine requires long
, instead of using machine dependent code, we replace it with generics and we'd just typedef long hello
, instead of typedef int hello
, and our code will be free from any architecture-specific dependency. Same with #define
Fundamentals Of C
>Mind Map of the Basics

>Basic Structure of a C program
#include <stdio.h> //preprocessor directives
#include <otherLibrairies>
int main() //main function initialisation, everything inside will be executed. Must be used only once
{
printf("My name is Rohit"); //statements // { } are terminal points of a function, and inside them is blocks of code
return 0;
}
>Comments
- Used to document our code
- Extraneous comments are bad, avoid them.
Single Line Comment
//This is a single line comment
Multi-line comment
/* This is a
multi
line
comment
*/
>Escape Characters
- Special characters which represent certain actions such as backspacing, going to the next line etc
- They must be enclosed within single quotes when assigned to a character variable, because a
char
data-type only accepts single quote
char x = '\\n';

Preprocessors and Headers
>Pre-Processing
- These special statements are identifier by the presence of the character
#
, and it must be the first non-spaced character in the line
- By using
#something
(pre-processor directive), we're giving an instruction to our compiler to do something with it before the compilation of the source code takes place
- Since they're dealt with, at the pre-processing phase, they don't have any global, local scope
- These pre-processor directives are restricted to just one line in length
>Header Files
- It defines information about some of the functions that are provided by that file
- They end with
.h
extensions
- Case-sensitive on some systems
- Normally, no executable code is there in the header files, no logic, only definitions of functions.
>The include preprocessor directive
A pre-processor directive, which instructs the compiler (#include <header.h>
) to include the contents of the header
library in our program.
/* < > tells the compiler to look for this
file in directories defined by $PATH*/
#include <stdio.h>
/*Used to include user-defined libraries,
Tells the compiler to look for a header file in the current directory*/
#include "stdio.h"
The basic Important Stuff