Revision of C Language
Revision of C Language
Introduction to C Language
o C has a small set of keywords and straightforward syntax, making it accessible to learn
and use.
2. Portable:
o Code written in C is highly portable and can be run on different types of machines with
minimal or no modification, which is why it’s often called a "machine-independent"
language.
3. Structured Programming:
o C has a wide variety of built-in functions, especially within its standard library, which
aids in various operations, from input/output (I/O) to complex math.
6. Extensibility:
o Users can define their own functions, which can then be used as if they were built-in,
allowing for extensibility.
• Origin: Developed in the 1970s by Dennis Ritchie at Bell Labs, primarily for the UNIX operating
system.
• Purpose: C was created as an improvement over B and BCPL (Basic Combined Programming
Language) to provide a language suitable for writing operating systems, making UNIX one of
its first major applications.
• Evolution: Over time, C has seen several updates, leading to standardized versions such as
ANSI C (C89) and ISO C (C90), with further improvements in C99, C11, and C18.
• Header Files: Files that include standard library functions, such as #include <stdio.h> for
standard I/O operations.
• Main Function: The entry point of a C program, where execution begins. Every C program must
have one main() function.
• Body: Contains statements, expressions, function calls, and control flow structures (e.g., loops
and conditionals).
Key Concepts in C
Variables are containers for data, and data types define the kind of data you can store in those
containers.
Declaring Variables:
When you declare a variable, you choose a type and give it a name.
2. Operators
Types of Operators:
..
3. Control Statements
Conditional Statements:
if Statement
The if statement checks if a condition is true, and if it is, the code inside it runs.
In this example, since age is 18, which meets the if condition (age >= 18), it will print "You are eligible
to vote.".
if-else Statement
This structure allows multiple conditions to be checked in sequence. Only the first true condition’s
code block will run.
In this example, since score is 75, the third condition (score >= 70) is true, so it prints "Grade: C".
switch Statement
The switch statement allows a variable to be tested against a list of values, with each case handling a
different value.
In this example, since day is 3, it will print "Wednesday".
2. Looping Statements
for Loop
The for loop runs a block of code a specific number of times, with three parts: initialization, condition,
and increment/decrement.
while Loop
The while loop runs as long as the condition is true. The loop checks the condition before running the
code inside it.
In this example, count starts at 1 and goes up to 5. The output will be the same as the for-loop example.
do-while Loop
The do-while loop is similar to the while loop, but it runs the code once before checking the condition.
This guarantees that the code inside the loop runs at least once.
However, if count started as 10, this loop would still run once and print "Count: 10" before checking
the condition.
3. Jump Statements
Jump statements help control the flow inside loops or blocks of code.
break Statement
The loop stops completely when i equals 3 because of the break statement.
continue Statement
The continue statement skips the rest of the code in the loop for the current iteration and moves to
the next iteration.
Here, the loop skips printing 3 and continues with the next iteration.
goto Statement
The goto statement allows you to jump to a labeled section of code. However, it’s rarely used because
it can make code hard to read and maintain.