0% found this document useful (0 votes)
7 views10 pages

Revision of C Language

The document provides an overview of the C programming language, highlighting its key features such as simplicity, efficiency, portability, and rich library support. It discusses the history and development of C, including its origins in the 1970s and subsequent standardizations. Additionally, the document outlines the basic structure of a C program, key concepts like variables, data types, operators, control statements, and looping statements.

Uploaded by

fnvnm7dm7x
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

Revision of C Language

The document provides an overview of the C programming language, highlighting its key features such as simplicity, efficiency, portability, and rich library support. It discusses the history and development of C, including its origins in the 1970s and subsequent standardizations. Additionally, the document outlines the basic structure of a C program, key concepts like variables, data types, operators, control statements, and looping statements.

Uploaded by

fnvnm7dm7x
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Revision of C Language

Introduction to C Language

Overview of C Language: C is a general-purpose, procedural programming language that was


developed in the early 1970s by Dennis Ritchie at Bell Laboratories. Known for its efficiency and
control, C is often used for system programming, such as writing operating systems and other low-level
code, but is versatile enough for application development as well.

Key Features of C Language

1. Simple and Efficient:

o C has a small set of keywords and straightforward syntax, making it accessible to learn
and use.

o It allows for low-level manipulation of data, making it efficient in terms of memory


and processing.

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 supports structured programming, which allows for clear, modular code


organization, using functions, loops, and conditionals to make code more readable and
manageable.

4. Low-Level Language Features:

o C provides low-level features similar to assembly language, such as pointers, which


allows for direct manipulation of memory and hardware.

5. Rich Library Support:

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.

History and Development of C

• 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.

Basic Structure of a C Program

A C program typically consists of:

• 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

1. Variables and Data Types

Variables are containers for data, and data types define the kind of data you can store in those
containers.

Common Data Types:

• int: For integers (whole numbers).

• float: For floating-point numbers (decimals), less precise.

• double: For more precise floating-point numbers.

• char: For single characters.

Declaring Variables:
When you declare a variable, you choose a type and give it a name.

Data Type Sizes and Memory:

Different data types take up different amounts of memory. For example:

• int usually takes 4 bytes.

• float takes 4 bytes.

• double takes 8 bytes (more precise).

• char takes 1 byte.

2. Operators

Operators perform actions on variables and values.

Types of Operators:
..

3. Control Statements

Control statements control the flow of a program.

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

if-else adds an else part that runs if the if condition is false.


In this example, since age is 16, the condition age >= 18 is false, so the program prints "You are not
eligible to vote.".

if-else 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

Looping statements allow a block of code to repeat multiple times.

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 break statement is used to exit a loop or switch statement early.

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.

You might also like