Programming in C: Introduction To C Language
Programming in C: Introduction To C Language
Introduction to C Language
The language of computers is – 0s and 1s.
Languages can be broadly classified into two categories – Low-
Level languages (such as Machine Language, etc.) and High-Level
languages (such as C, C++, etc.).
C language was developed by Dennis Ritchie in 1972 at Bell
Laboratories.
C is a successor of the B language.
C is the most popular and widely-used programming language.
After it’s development, it was standardized by ANSI in 1989.
C is a compiler-based language.
The C program is written in a .c file. Then, a compiler converts the
high-level code to bunch of zeros and ones (object code), which
the machine can understand.
Independent of
Dependent on Architecture. Architecture but might be
OS dependent.
Language Translators
There are three types of language translators:
o Assembler (Converts Assembly Language to Machine Code)
o Compiler (Converts High-Level Language)
o Interpreter (Converts High-Level Language)
The difference between compiler and interpreter is, compiler
executes the program after complete translation, whereas
interpreter converts and executes parallelly, line-by-line.
Compiler creates an object code while interpreter directly gives the
output.
Features of C Language
It’s a High-Level Language.
It’s a small language with only 32 keywords.
Most of the languages are dependent on C.
It’s portable.
It has a few built-in functions and operators.
It has access to pointers.
It’s an extensible, structured and modular language.
It allows dynamic memory allocation paradigms.
It’s compilation and execution is faster.
It’s a case sensitive language.
It’s used to develop and operate embedded systems. That’s why
it’s also known as system programming language.
Structure of a C Program
1. Documentation Section – Compiler ignores this part. It is solely
done to help the fellow developers out.
a. Single Line Comment - //
b. Multiple Line Comments - /* … */
2. Link Section – Basically importing header files (aka libraries) to use
the functions.
a. #include<stdio.h>
b. #include<conio.h>
c. #include<math.h>
d. #include<string.h>
e. #include<stdlib.h>
3. Definition Section - #define variable_name value
4. Global Declaration Section – Declaring global variables (outside the
functions).
5. Main Section – Code control always goes to the main function first.
(datatype main() { … }).
6. Sub-program functions – User defined functions.
Variables in C
Variables are basically a named memory location which is used to
store a value of a data.
First step to creating a variable is declaring the datatype of the
variable names.
Example: char, int, float, double, etc.
The datatype of a variable cannot be void.
Variable names cannot have spaces or special characters. It can
also not start with a number or underscore.
Datatypes in C
Datatypes denote the type of data and size of memory to be
allocated.
There are three types of data types:
o Primary – Built-in/fundamental
Examples: int, float, char, void, double
o Derived – Derived using primary data types, etc.
Examples: array, structure, union and pointers
o User-defined – typedef and enumerated.
int – short int and long int + unsigned int and signed int (4
qualifiers - common).
The size of the datatype depends upon the compilers in some
cases. To get the size, run: printf(“%d”, sizeof(int)).