History of C Language
History of C Language
History of C Language
History of C
Languages such as C++/Java are developed from ‘C’. These languages are
widely used in various technologies. Thus, ‘C’ forms a base for many other
languages that are currently in use.
C programming
C language combines the power of a low-level language and a high-level language.
The low-level languages are used for system programming, while the high-level
languages are used for application programming. It is because such languages are
flexible and easy to use. Hence, C language is a widely used computer language.
basic structure of a C program. A C program is divided into different sections. There are
six main sections to a basic c program.
Documentation
Link
Definition
Global Declarations
Main functions
Subprograms
Documentation Section
The documentation section is the part of the program where the programmer gives the
details associated with the program. He usually gives the name of the program, the
details of the author and other details like the time of coding and description.
Example
/**
* date: 09/08/2019
*/
Link Section
This part of the code is used to declare all the header files that will be used in the
program. This leads to the compiler being told to link the header files to the system
libraries.
Example
1 #include<stdio.h>
Moving on to the next bit of this basic structure of a C program article,
Definition Section
In this section, we define different constants. The keyword define is used in this part.
1 #define PI=3.14
Moving on to the next bit of this basic structure of a C program article,
1 int main(void)
2 {
3 int a=10;
4 printf(" %d", a);
return 0;
5
}
6
C Character Set
As every language contains a set of characters used to construct words, statements, etc., C
language also has a set of characters which include alphabets, digits, and special symbols. C
Every C program contains statements. These statements are constructed using words and these
words are constructed using characters from C character set. C language character set contains the
1. Alphabets
2. Digits
3. Special Symbols
Alphabets
C language supports all the alphabets from the English language. Lower and upper case letters
C language supports 10 digits which are used to construct numerical values in C language.
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols
C language supports a rich set of special symbols that include symbols to perform mathematical
operations, to check conditions, white spaces, backspaces, and other special symbols.
Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , < \ | tab newline space NULL bell
Every character in C language has its equivalent ASCII (American Standard Code for Information
Interchange) value.
Commonly used characters in C with thier ASCII values
C Tokens
Every C program is a collection of instructions and every instruction is a collection of some individual
units. Every smallest individual unit of a c program is called token. Every instruction in a c program is
a collection of tokens. Tokens are used to construct c programs and they are said to the basic
1. Keywords
2. Identifiers
3. Operators
4. Special Symbols
5. Constants
6. Strings
7. Data values
C Keywords
As every language has words to construct statements, C programming also has words with a
specific meaning which are used to construct c program instructions. In the C programming
language, keywords are special words with predefined meaning. Keywords are also known as
In the C programming language, there are 32 keywords. All the 32 keywords have their meaning
compiler
Properties of Keywords
1. All the keywords in C programming language are defined as lowercase letters so they must
be used only in lowercase letters
2. Every keyword has a specific meaning, users can not change that meaning.
3. Keywords can not be used as user-defined names like variable, functions, arrays, pointers,
etc...
4. Every keyword in C programming language represents something or specifies some kind of
action to be performed by the compiler.
Keywords in C Programming
C Identifiers
In C programming language, programmers can specify their name to a variable, array, pointer,
function, etc... An identifier is a collection of characters which acts as the name of variable, function,
array, pointer, structure, etc... In other words, an identifier can be defined as the user-defined name
to identify an entity uniquely in the c programming language that name may be of the variable name,
The identifier is a user-defined name of an entity to identify it uniquely during the program
execution
Example
int marks;
char studentName[30];
Here, marks and studentName are identifiers.
lowercase), numerics & underscore symbol only.
2. An identifier should not start with a numerical value. It can start with a letter or an
underscore.
3. We should not use any special symbols in between the identifier even whitespace. However,
5. There is no limit for the length of an identifier. However, the compiler considers the first 31
characters only.
C Variables
Variables in a c programming language are the named memory locations where the user can store
different values of the same datatype during the program execution. That means a variable is a
name given to a memory location in which we can store different values of the same data type. In
other words, a variable can be defined as a storage container to hold values of the same datatype
during the program execution. The formal definition of a data type is as follows...
Variable is a name given to a memory location where we can store different values of the
Every variable in c programming language must be declared in the declaration section before it is
used. Every variable must have a datatype that determines the range and type of values be stored
and the size of the memory to be allocated.
A variable name may contain letters, digits and underscore symbol. The following are the rules to
specify a variable name...
Declaration of Variable
Declaration of a variable tells the compiler to allocate the required amount of memory with the
specified variable name and allows only specified datatype values into that memory location. In C
programming language, the declaration can be performed either before the function as global
variables or inside any block or function. But it must be at the beginning of block or function.
Declaration Syntax:
datatype variableName;
Example
int number;
The above declaration tells to the compiler that allocates 2 bytes of memory with the
name number and allows only integer values into that memory location.
C data types
Data used in c program is classified into different types based on its properties. In the C
programming language, a data type can be defined as a set of values with similar characteristics. All
variable. The memory size and type of the value of a variable are determined by the variable data
type. In a c program, each variable or constant or array must have a data type and this data type
specifies how much memory is to be allocated and what type of values are to be stored in that
The Data type is a set of value with predefined characteristics. data types are used to declare
float
double
We use the keyword "float" to represent floating-point data type and "double" to represent double
data type in c. Both float and double are similar but they differ in the number of decimal places. The
float value contains 6 decimal places whereas double value contains 15 or 19 decimal places. The
following table provides complete details about floating-point data types.
Character data type
The character data type is a set of characters enclosed in single quotations. The following table
provides complete details about the character data type.
The following table provides complete information about all the data types in c programming
language...
void data type
The void data type means nothing or no value. Generally, the void is used to specify a function
which does not return any value. We also use the void data type to specify empty parameters of a
function.
Arrays
Structures
Unions
Enumeration
C Constants
In C programming language, a constant is similar to the variable but the constant hold only one
value during the program execution. That means, once a value is assigned to the constant, that
value can't be changed during the program execution. Once the value is assigned to the constant, it
A constant is a named memory location which holds only one value throughout the program
execution.
In C programming language, a constant can be of any data type like integer, floating-point,
character, string and double, etc.,
Integer constants
An integer constant can be a decimal integer or octal integer or hexadecimal integer. A decimal
integer value is specified as direct integer value whereas octal integer value is prefixed with 'o' and
hexadecimal value is prefixed with 'OX'.
An integer constant can also be unsigned type of integer constant or long type of integer constant.
Unsigned integer constant value is suffixed with 'u' and long integer constant value is suffixed with 'l'
whereas unsigned long integer constant value is suffixed with 'ul'.
Example
125 -----> Decimal Integer Constant
O76 -----> Octal Integer Constant
OX3A -----> Hexa Decimal Integer Constant
50u -----> Unsigned Integer Constant
30l -----> Long Integer Constant
100ul -----> Unsigned Long Integer Constant
Floating Point constants
A floating-point constant must contain both integer and decimal parts. Some times it may also
contain the exponent part. When a floating-point constant is represented in exponent form, the value
must be suffixed with 'e' or 'E'.
Example
The floating-point value 3.14 is represented as 3E-14 in exponent form.
Character Constants
A character constant is a symbol enclosed in single quotation. A character constant has a maximum
length of one character.
Example
'A'
'2'
'+'
In the C programming language, there are some predefined character constants called escape
sequences. Every escape sequence has its own special functionality and every escape sequence is
prefixed with '\' symbol. These escape sequences are used in output function called 'printf()'.
String Constants
A string constant is a collection of characters, digits, special symbols and escape sequences that are
enclosed in double quotations.
We can also define string constant by separating it with white space as follows...
"This" "is" "btechsmartclass"
Creating constants in C
In a c programming language, constants can be created using two concepts...
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i = 9 ;
const int x = 10 ;
i = 15 ;
x = 100 ; // creates an error
printf("i = %d\nx = %d", i, x ) ;
}
The above program gives an error because we are trying to change the constant variable value (x =
100).
Example Program
#include<stdio.h>
#include<conio.h>
#defien PI 3.14
void main(){
int r, area ;
area = PI * (r * r) ;
C Operators
An operator is a symbol used to perform arithmetic and logical operations in a program. That means
an operator is a special symbol that tells the compiler to perform mathematical or logical operations.
C programming language supports a rich set of operators that are classified as follows.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
5. Assignment Operators
6. Bitwise Operators
7. Conditional Operator
8. Special Operators
The arithmetic operators are the symbols that are used to perform basic mathematical operations
like addition, subtraction, multiplication, division and percentage modulo. The following table
+ Addition 10 + 5 = 15
- Subtraction 10 - 5 = 5
* Multiplication 10 * 5 = 50
/ Division 10 / 5 = 2
⇒ The addition operator can be used with numerical data types and character data type. When it is
used with numerical values, it performs mathematical addition and when it is used with character
⇒ The remainder of the division operator is used with integer data type only.
Relational Operators (<, >, <=, >=, ==, !=)
The relational operators are the symbols that are used to compare two values. That means the
relational operators are used to check the relationship between two values. Every relational operator
has two results TRUE or FALSE. In simple words, the relational operators are used to define
conditions in a program. The following table provides information about relational operators.
Operator Meaning
< Returns TRUE if the first value is smaller than second value otherwise returns FALSE
> Returns TRUE if the first value is larger than second value otherwise returns FALSE
<= Returns TRUE if the first value is smaller than or equal to second value otherwise returns FALSE
>= Returns TRUE if the first value is larger than or equal to second value otherwise returns FALSE
!= Returns TRUE if both values are not equal otherwise returns FALSE
The logical operators are the symbols that are used to combine multiple conditions into one
&& Logical AND - Returns TRUE if all conditions are TRUE otherwise returns FALSE 10 < 5 &&
|| Logical OR - Returns FALSE if all conditions are FALSE otherwise returns TRUE 10 < 5 ||
! Logical NOT - Returns TRUE if condition is FLASE and returns FALSE if it is TRUE !(10 < 5 &
⇒ Logical AND - Returns TRUE only if all conditions are TRUE, if any of the conditions is FALSE
⇒ Logical OR - Returns FALSE only if all conditions are FALSE, if any of the conditions is TRUE
The increment and decrement operators are called unary operators because both need only one
operand. The increment operators adds one to the existing value of the operand and the decrement
operator subtracts one from the existing value of the operand. The following table provides
Operator Meaning Ex
Pre-Increment or Pre-Decrement
In the case of pre-increment, the value of the variable is increased by one before the expression
evaluation. In the case of pre-decrement, the value of the variable is decreased by one before the
expression evaluation. That means, when we use pre-increment or pre-decrement, first the value of
the variable is incremented or decremented by one, then the modified value is used in the
expression evaluation.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i = 5,j;
j = ++i; // Pre-Increment
Output:
Post-Increment or Post-Decrement
In the case of post-increment, the value of the variable is increased by one after the expression
evaluation. In the case of post-decrement, the value of the variable is decreased by one after the
expression evaluation. That means, when we use post-increment or post-decrement, first the
expression is evaluated with existing value, then the value of the variable is incremented or
decremented by one.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i = 5,j;
j = i++; // Post-Increment
Output:
Assignment Operators (=, +=, -=, *=, /=, %=)
The assignment operators are used to assign right-hand side value (Rvalue) to the left-hand side
variable (Lvalue). The assignment operator is used in different variants along with arithmetic
operators. The following table describes all the assignment operators in the C programming
language.
Operator Meaning
+= Add both left and right-hand side values and store the result into left-hand side variable
-= Subtract right-hand side value from left-hand side variable value and store the result
into left-hand side variable
*= Multiply right-hand side value with left-hand side variable value and store the result
into left-hand side variable
Operator Meaning
/= Divide left-hand side variable value with right-hand side variable value and store the result
into the left-hand side variable
%= Divide left-hand side variable value with right-hand side variable value and store the remainder
into the left-hand side variable
The bitwise operators are used to perform bit-level operations in the c programming language. When
we use the bitwise operators, the operations are performed based on the binary values. The
following table describes all the bitwise operators in the C programming language.
Operator Meaning
& the result of Bitwise AND is 1 if all the bits are 1 otherwise it is 0
^ the result of Bitwise XOR is 0 if all the bits are same otherwise it is 1
<< the Bitwise left shift operator shifts all the bits to the left by the specified number of positions
Operator Meaning
>> the Bitwise right shift operator shifts all the bits to the right by the specified number of positions
The conditional operator is also called a ternary operator because it requires three operands. This
operator is used for decision making. In this operator, first we verify a condition, then we perform one
operation out of the two operations based on the condition result. If the condition is TRUE the first
option is performed, if the condition is FALSE the second option is performed. The conditional
Example
This operator is used to find the size of the memory (in bytes) allocated for a variable. This operator
sizeof(variableName);
Example
This operator is used to separate variables while they are declaring, separate the expressions in
Generally, the programs created using programming languages like C, C++, Java, etc., are written
using a high-level language like English. But, the computer cannot understand the high-level
language. It can understand only low-level language. So, the program written in the high-level
language needs to be converted into the low-level language to make it understandable for the
Popular programming languages like C, C++, Java, etc., use the compiler to convert high-level
language instructions into low-level language instructions. A compiler is a program that converts
high-level language instructions into low-level language instructions. Generally, the compiler
performs two things, first it verifies the program errors, if errors are found, it returns a list of errors
To create and execute C programs in the Windows Operating System, we need to install Turbo C
software. We use the following steps to create and execute C programs in Windows OS…
Source code is a file with C programming instructions in a high-level language. To create source
code, we use any text editor to write the program instructions. The instructions written in the source
code must follow the C programming language rules. The following steps are used to create a
Click on the Start button
Select Run
Type cmd and press Enter
Type TC press Enter
Type the program
The compilation is the process of converting high-level language instructions into low-level language
The compilation is the process of converting high-level language instructions into low-level
language instructions.
Whenever we press Alt + F9, the source file is going to be submitted to the Compiler. On receiving a
source file, the compiler first checks for the Errors. If there are any Errors then compiler returns List
of Errors, if there are no errors then the source code is converted into object code and stores it as a
file with .obj extension. Then the object code is given to the Linker. The Linker combines both
the object code and specified header file code and generates an Executable file with
a .exe extension.
We use a shortcut key Ctrl + F9 to run a C program. Whenever we press Ctrl + F9, the .exe file is
submitted to the CPU. On receiving .exe file, CPU performs the task according to the instruction
written in the file. The result generated from the execution is placed in a window called User Screen.
Whenever we press Alt + F9 the source file is submitted to the compiler. Compiler checks for the
errors, if there are any errors, it returns a list of errors, otherwise generates object code in a file with
name Sample.obj and submit it to the linker. The linker combines the code from specified header file
into an object file and generates executable file as Sample.exe. With this compilation process
completes.
Now, we need to run the executable file (Sample.exe). To run a program we press Ctrl + F9. When
we press Ctrl + F9 the executable file is submitted to the CPU. Then CPU performs the task
according to the instructions written in that program and place the result into UserScreen.
Then we press Alt + F5 to open UserScreen and check the result of the program.
Important Points
C program file (Source file) must save with .c extension.
The compiler converts complete program at a time from high-level language to low-level
language.
Input to the compiler is .c file and output from the compiler is .exe file, but it also
generates .obj file in this process.
The compiler converts the file only if there are no errors in the source code.
CPU places the result in User Screen window.
Overall Process
Type the program in C editor and save with .c extension (Press F2 to save).
Press Alt + F9 to compile the program.
If there are errors, correct the errors and recompile the program.
If there are no errors, then press Ctrl + F9 to execute/run the program.
Press Alt + F5 to open User Screen and check the result.
C Input Functions
C programming language provides built-in functions to perform input operations. The input
operations are used to read user values (input) from the keyboard. The c programming language
1. scanf()
2. getchar()
3. getch()
4. gets()
5. fscanf()
scanf() function
The scanf() function is used to read multiple data values of different data types from the keyboard.
The scanf() function is built-in function defined in a header file called "stdio.h". When we want to use
scanf() function in our program, we need to include the respective header file (stdio.h)
Syntax:
scanf("format strings",&variableNames);
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i;
printf("\nEnter any integer value: ");
scanf("%d",&i);
printf("\nYou have entered %d number",i);
Output:
In the above example program, we used the scanf() function to read an integer value from the
The scanf function also used to read multiple data values of different or the same data types.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i;
float x;
printf("\nEnter one integer followed by one float value : ");
scanf("%d%f",&i, &x);
printf("\ninteger = %d, float = %f",i, x);
Output:
In the above example program, we used the scanf() function to read one integer value and one float
value from the keyboard. Here 'i' is an integer variable so we have used format string %d, and 'x' is
The scanf() function returns an integer value equal to the total number of input values read using
scanf function.
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
int i,a,b;
float x;
printf("\nEnter two integers and one float : ");
i = scanf("%d%d%f",&a, &b, &x);
printf("\nTotal inputs read : %d",i);
Output:
getchar() function
The getchar() function is used to read a character from the keyboard and return it to the program.
This function is used to read a single character. To read multiple characters we need to write
multiple times or use a looping statement. Consider the following example program...
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
char ch;
printf("\nEnter any character : ");
ch = getchar();
printf("\nYou have entered : %c\n",ch);
Output:
getch() function
The getch() function is similar to getchar function. The getch() function is used to read a character
from the keyboard and return it to the program. This function is used to read a single character. To
read multiple characters we need to write multiple times or use a looping statement. Consider the
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
char ch;
printf("\nEnter any character : ");
ch = getch();
printf("\nYou have entered : %c",ch);
Output:
gets() function
The gets() function is used to read a line of string and stores it into a character array. The gets()
function reads a line of string or sequence of characters till a newline symbol enters. Consider the
Example Program
#include<stdio.h>
#include<conio.h>
void main(){
char name[30];
printf("\nEnter your favourite website: ");
gets(name);
printf("%s",name);
}
Output:
fscanf() function
The fscanf() function is used with the concept of files. The fscanf() function is used to read data
values from a file. When you want to use fscanf() function the file must be opened in reading mode.