From
Algol to Traditional C
1.
Algol (Algorithmic Language)
- Year:
1950s
- What is it:
Algol was one of the earliest high-level programming languages. It was
used mainly for mathematical and scientific computations.
- Importance:
Algol laid the foundation for the structure and syntax of many modern
programming languages.
2.
BCPL (Basic Combined Programming Language)
- Year:
1966
- Developer:
Martin Richards
- What is it:
BCPL was a simple and powerful language designed for system programming.
It served as a foundation for the development of the C language.
3.
B Language
- Year:
1969
- Developer:
Ken Thompson
- What is it:
The B language was derived from BCPL. It was developed for the UNIX
operating system. While useful, B was limited in features.
4.
C Language
- Year:
1972
- Developer:
Dennis Ritchie
- What is it:
- C was developed at Bell Labs.
- The goal was to create a powerful low-level language
for system programming, particularly for the UNIX operating system.
- It evolved from the B language and added new features
like data types, functions, etc.
- C made programming more efficient, powerful, and
portable.
5.
Traditional C
- Year:
1978
- Famous Book:
The C Programming Language by Dennis Ritchie and Brian Kernighan
- What is it:
- This book provided the first comprehensive explanation
of the C language.
- It’s often referred to as the "Kernighan and
Ritchie" book.
- This version of C is known as ‘Traditional C’ or
‘K&R C’.
- It was the first stable and widely accepted standard
of the C language.
Key
Contributors in the Development of C Language
Name |
Contribution |
Dennis Ritchie |
Inventor of the C language;
co-developer of UNIX OS. |
Ken Thompson |
Creator of B language; co-developer
of UNIX OS. |
Martin Richards |
Developer of BCPL, which
influenced C’s development. |
Brian Kernighan |
Co-author of the famous C book;
helped spread the language. |
In
Summary
- Algol
→ The base language that influenced modern languages.
- BCPL
→ A simple system-level programming language.
- B Language
→ A modified version of BCPL, created for UNIX.
- C Language
→ Developed by Dennis Ritchie; powerful, portable, and efficient.
- Traditional C
→ The first standard version of C, documented in 1978.
History
of C Language
- The C language was developed by Dennis Ritchie in
1972 at Bell Labs (USA).
- It was created for the development of the Unix
Operating System.
- C was developed from the B language, which was
an earlier programming language.
- The popularity of C grew rapidly, and it is still
used today to develop many systems and applications.
Advantages
of C Language
- Fast and Efficient:
C is a very fast language and uses minimal system resources. - Best for System Programming:
Ideal for creating operating systems, drivers, etc. - Structured Programming:
Helps organize code into functions, making programming simpler. - Strong Foundation for Other Languages:
Learning C makes it easier to learn other languages like C++, Java, and Python. - Close to Hardware:
Allows direct control over memory and hardware.
Disadvantages
of C Language
- Not Object-Oriented:
It does not support the concept of classes and objects. - Less Secure:
Manual memory management can lead to errors and vulnerabilities. - No Built-in GUI Support:
Requires additional libraries for graphics or user interface. - Error Handling is Difficult:
Compared to other languages, detecting and handling errors is more challenging.
Procedure
Oriented Programming (POP)
In procedure-oriented programming, a
program is divided into small functions or procedures. It focuses more on process
or logic than on data.
Features:
- Data and functions are kept separate.
- Code reuse is difficult.
- Traditional way of programming.
- Examples:
C, Pascal, FORTRAN, etc.
Object
Oriented Programming (OOP)
In object-oriented programming, the
program is structured around objects. It organizes data and the
functions that operate on that data into classes.
Features:
- Combines data and functions into a single object.
- Easier code reusability and scalability.
- Supports modern features like encapsulation and inheritance.
- Examples:
C++, Java, Python, C#, etc.
Difference
between POP and OOP
Feature |
Procedure-Oriented
Programming (POP) |
Object-Oriented
Programming (OOP) |
1. Basis |
Based on Process |
Based on Object |
2. Data Security |
Data is not secure |
Data is secure
(Encapsulation) |
3. Structure |
Functions and data are separate |
Functions and data are together
in objects |
4. Reusability |
Code reusability is difficult |
Code reusability is easy |
5. Examples |
C, Pascal, FORTRAN |
C++, Java, Python |
6. Complexity Management |
Difficult to manage large
programs |
Easy to manage large programs |
7. Development Approach |
Traditional |
Modern |
1.
Character Set in C Language
To write programs in the C
language, a specific set of characters is used. This set is called the Character
Set, and it consists of the following types:
(i)
Letters:
- Small Letters:
a to z
- Capital Letters:
A to Z
(ii)
Digits:
- 0 to 9
(iii)
Special Characters:
Special
Character |
Name
in English |
Name
in Hindi |
! |
Exclamation mark |
विस्मयादिबोधक चिन्ह |
@ |
At symbol |
ऐट चिन्ह |
# |
Hash / Number sign |
हैश / संख्या
चिन्ह |
$ |
Dollar sign |
डॉलर चिन्ह |
% |
Percent sign |
प्रतिशत चिन्ह |
^ |
Caret |
कैरेट (घात
के लिए) |
& |
Ampersand |
एंड / संयोजन
चिन्ह |
* |
Asterisk |
तारक चिन्ह
/ गुणा चिन्ह |
( |
Left parenthesis |
बाँया कोष्ठक
(ब्रैकेट) |
) |
Right parenthesis |
दायाँ कोष्ठक
(ब्रैकेट) |
- |
Hyphen / Minus |
ऋण चिन्ह
/ माइनस |
_ |
Underscore |
अधोरेखा |
= |
Equal sign |
समानता चिन्ह |
+ |
Plus sign |
जोड़ चिन्ह
/ प्लस |
{ |
Left curly brace |
बाँया घुंघराला ब्रैकेट |
} |
Right curly brace |
दायाँ घुंघराला ब्रैकेट |
[ |
Left square bracket |
बाँया वर्ग कोष्ठक |
] |
Right square bracket |
दायाँ वर्ग कोष्ठक |
: |
Colon |
कोलन |
; |
Semicolon |
अर्धविराम |
" |
Double quote |
डबल कोट्स |
' |
Single quote |
सिंगल कोट्स |
< |
Less than |
से कम |
> |
Greater than |
से अधिक |
, |
Comma |
अल्पविराम |
. |
Period / Dot |
पूर्णविराम / बिंदु |
? |
Question mark |
प्रश्नवाचक चिन्ह |
/ |
Forward slash |
स्लैश / भाग
चिन्ह |
\ |
Backslash |
बैकस्लैश |
` |
Backtick |
वक्र उच्चारण चिन्ह (used
rarely) |
` |
` |
Vertical bar / Pipe |
~ |
Tilde |
टिल्ड (~) |
(iv)
White Spaces:
- Space
- Tab
- New Line (Enter)
·
Keywords
·
Definition:
Keywords are reserved words that have special meanings in the C
language and are used for specific purposes. They cannot be used as variable or
function names.
·
List of 32
Major Keywords in C:
·
cpp
·
CopyEdit
·
auto break case char
·
const continue
default
do
·
double else enum extern
·
float for goto if
·
int long register
return
·
short signed
sizeof static
·
struct switch
typedef
union
·
unsigned
void volatile
while
·
Identifier
·
In C language, an Identifier
is the name used to identify variables, functions, arrays, structures,
etc.
·
Rules for
Writing Identifiers in C:
S.No. |
Rule |
Explanation |
1 |
Only letters (A-Z, a-z), digits
(0-9), and the underscore (_) symbol can be used. |
However, the name must not
begin with a digit. |
2 |
The identifier must start with a letter
or underscore (_) only. |
Example: _count, name1 are valid; 1name is invalid. |
3 |
C keywords cannot be used
as identifiers. |
For example: int,
return, while cannot be used as names. |
4 |
Identifiers in C are case-sensitive. |
Marks and marks are considered different. |
5 |
The name of an identifier should
be meaningful and clear. |
Example: totalMarks is better than tm. |
6 |
The maximum length of an
identifier depends on the C compiler. |
DATA
TYPES:
1.
Primary (Fundamental) Data Types (for 32-bit systems)
Data
Type |
Value
Range |
char |
-128 to 127 |
unsigned char |
0 to 255 |
int |
-2,14,74,83,648 to 2,14,74,83,647 |
unsigned int |
0 to 4,29,49,67,295 |
short int |
-32,768 to 32,767 |
long int |
Approximately -2 billion to +2
billion |
float |
Accuracy up to approximately 6
decimal digits |
double |
Accuracy up to approximately 15 decimal
digits |
Key
Notes:
- The char type is actually an integer type used to store
the ASCII values of characters.
- short, int, long, and long
long are all used for integer
values, but with different ranges.
- The unsigned type does not allow negative values.
- float, double, and long
double are used to store decimal
(floating-point) values.
2.
User-Defined Data Types
These are defined by the programmer:
- struct (Structure)
- union (Union)
- enum (Enumeration)
- typedef (Used to create new type names)
3.
Derived Data Types
These are created from fundamental
types:
- Array:
A group of elements of the same type — e.g., int arr[5];
- Pointer:
Stores the address of a variable — e.g., int *ptr;
- Function:
Returns a value — e.g., int
sum(int a, int b);
- Structure/Union:
User-defined data types
Operator
An operator is a symbol
that performs an operation on variables or values.
Example:
int a = 5 + 3;
Here, + is an operator that adds 5 and 3.
Main
Types of Operators in C Language:
1.
Arithmetic Operators
Operator |
Meaning |
Example
(a = 10, b = 5) |
Output |
+ |
Addition |
a + b |
15 |
- |
Subtraction |
a - b |
5 |
* |
Multiplication |
a * b |
50 |
/ |
Division |
a / b |
2 |
% |
Modulus (Remainder) |
a % b |
0 |
2.
Relational Operators
These operators compare two values
and return true (1) or false (0).
Operator |
Meaning |
Example
(a = 10, b = 5) |
Output |
== |
Equal to? |
a == b |
0 |
!= |
Not equal to? |
a != b |
1 |
> |
Greater than? |
a > b |
1 |
< |
Less than? |
a < b |
0 |
>= |
Greater or equal? |
a >= b |
1 |
<= |
Less or equal? |
a <= b |
0 |
3.
Logical Operators
Used to combine or test conditions:
Operator |
Name |
Meaning |
&& |
AND |
True only if both
conditions are true |
` |
` |
|
! |
NOT |
Reverses the result: true becomes
false, and vice versa |
Example:
(a > 5 && b < 10)
// returns true (1)
4.
Assignment Operators
Operator |
Meaning |
Example |
= |
Assign value |
a = 5 |
+= |
Add and assign |
a += 3 → a
= a + 3 |
-= |
Subtract and assign |
a -= 2 → a
= a - 2 |
*= |
Multiply and assign |
a *= 4 |
/= |
Divide and assign |
a /= 2 |
5.
Increment & Decrement Operators
Operator |
Meaning |
Example |
++ |
Increment by 1 |
a++ or ++a |
-- |
Decrement by 1 |
a-- or --a |
6.
Bitwise Operators
Bitwise operators in C perform operations on the binary bits of
numbers. They work bit-by-bit, not on the entire number at once.
1.
& (Bitwise AND)
Compares bits of both operands and
returns 1 only if both bits are 1.
Example:
int a = 5;
// Binary: 0101
int b = 3;
// Binary: 0011
int c = a & b; // Result:
0001 (Decimal: 1)
2.
| (Bitwise OR)
Returns 1 if any one bit is 1.
Example:
int a = 5;
// Binary: 0101
int b = 3;
// Binary: 0011
int c = a | b; // Result:
0111 (Decimal: 7)
3.
^ (Bitwise XOR)
Returns 1 if the bits are
different (one is 0 and the other is 1).
Example:
int a = 5;
// Binary: 0101
int b = 3;
// Binary: 0011
int c = a ^ b; // Result:
0110 (Decimal: 6)
4.
~ (Bitwise NOT)
A unary operator that inverts
each bit (0 becomes 1, and 1 becomes 0).
Note: The result is shown in 2's complement form, so it
may appear as a negative number for signed integers.
Example:
int a = 5;
// Binary: 0101
int c = ~a; // Result:
1010 → Output: -6 (in 2's complement)
5.
<< (Left Shift)
Shifts all bits to the left,
and fills 0s on the right.
Example:
int a = 5;
// Binary: 0101
int c = a << 1;
// Result: 1010 (Decimal: 10)
6.
>> (Right Shift)
Shifts all bits to the right,
and the leftmost bit is filled with the sign bit.
Example:
int a = 5;
// Binary: 0101
int c = a >> 1;
// Result: 0010 (Decimal: 2)
Conditional
Operator (Ternary Operator)
The Conditional Operator in C
is also called the Ternary Operator because it works with three
operands. It provides a shortcut for if-else statements.
Syntax:
condition ? expression_if_true :
expression_if_false;
- condition → A valid logical or comparison expression.
- If the condition is true, expression_if_true is executed.
- If the condition is false, expression_if_false is executed.
Example:
#include <stdio.h>
int main() {
int a = 10, b = 20;
int max;
max = (a > b) ? a : b;
printf("The larger value is:
%d\n", max);
return 0;
}
sizeof
Operator
The sizeof operator is a unary compile-time
operator that tells the memory size (in bytes) of a data type or
variable.
Syntax:
sizeof(type)
or
sizeof(variable)
It tells the compiler how much
memory a data type or variable occupies.
Example:
#include <stdio.h>
int main() {
int a;
float b;
char c;
double d;
printf("Size of int: %lu bytes\n", sizeof(a));
printf("Size of float: %lu
bytes\n", sizeof(b));
printf("Size of char: %lu
bytes\n", sizeof(c));
printf("Size of double: %lu
bytes\n", sizeof(d));
return 0;
}
Note:
- %lu is used for unsigned long
because sizeof returns a value of type size_t,
which is an unsigned integer.
Definition:
A statement is an instruction
that the compiler executes.
A C program is made up of multiple statements, and each statement
performs a specific task.
Every C statement ends with a semicolon (;).
Types of Statements in C:
1.
Expression Statement
- Executes an expression.
- Example:
a = b + 5;
i++;
2.
Declaration Statement
- Declares a variable or function.
- Example:
int x;
float pi;
3.
Compound Statement (Block)
- A group of multiple statements enclosed in curly
braces {}.
- Example:
{
int a = 10;
a = a + 5;
printf("%d", a);
}
4.
Control Flow Statements
- These statements control the flow of the
program.
- Sub-types include:
- Selection statements → if, if-else, switch
- Looping statements → for, while, do-while
- Jump statements
→ break, continue, goto, return
5.
Null Statement
- Just a semicolon ; — does nothing.
- Example:
;
Example
Program:
#include <stdio.h>
int main() {
int a = 10; //
Declaration + Expression Statement
if (a > 5) { //
Selection Statement
printf("a is
big"); // Expression
Statement
}
return 0; //
Jump Statement
}
No comments:
Post a Comment