You are on page 1of 4

--- C LANGUAGE

---- What is C Language?


- **Definition:** C is a general-purpose programming language created by Dennis Ritchie at Bell
Laboratories in 1972.
- **Origin:** Derived from the earlier language "B" (Basic Combined Programming Language –
BCPL) and initially invented for implementing the UNIX operating system.

---- Features and Uses of C Language:


- **Reliability:** Known for its reliability in building robust and efficient programs.
- **Portability:** C programs can run on various platforms with minimal changes.
- **Flexibility:** Offers flexibility in coding and allows low-level access to system resources.
- **Interactivity:** Supports interactive programming with direct user input and output.
- **Modularity:** Encourages modular programming, allowing code organization into
manageable modules.
- **Efficiency and Effectiveness:** Provides high performance and efficiency in program
execution.

---- Levels of Programming Languages:


- **Middle Level:** Examples include C and C++, providing a balance between high-level and
low-level functionalities.
- **High Level:** Languages like Java and Python offer extensive built-in functions and features.
- **Low Level:** Assembler is an example, providing direct access to machine instructions.

---- Types of Languages:


- **Structure Oriented Language:** Focuses on dividing large programs into smaller functions,
following a top-down approach. Examples include C and Pascal.
- **Object-Oriented Language:** Programs are divided into objects, focusing on data rather than
functions, following a bottom-up approach. Examples include C++, Java, and C-.

--- BASIC INPUT AND OUTPUT IN C

---- C Basic Commands Explanation:


- **-include <stdio.h>:** Preprocessor command to include the standard input-output header file
from the C library.
- **int main():** Main function where the execution of any C program begins.
- **{ ... }:** Indicates the beginning and end of the main function block.
- **/* ... */:** Comments that are ignored during compilation and execution.
- **printf():** Command to print output onto the screen.
- **getch() / getche():** Commands to wait for character input from the keyboard.
- **return 0:** Terminates the C program (main function) and returns 0.

--- C VARIABLES, DATA TYPES, OPERATORS, AND FORMULAS


---- C Variables:
- **Definition:** Containers for storing data values like numbers and characters.
- **Types:** Includes int (for integers), float (for floating-point numbers), and char (for single
characters).
- **Naming Rules:** Must begin with a letter or underscore, case-sensitive, and constructed with
letters, digits, or underscores.

---- Format Specifiers:


- **Used with printf():** Specify the type of data a variable is storing.
- **Examples:** %d for int, %f for float, %c for char, and %s for strings.

---- Data Types:


- **Definition:** Collection of data values with specified sizes and operations.
- **Basic Data Types:** Include int, float, double, and char, with different sizes and uses.

---- Operators:
- **Categorization:** Arithmetic, assignment, comparison, logical, and bitwise operators.
- **Functionality:** Perform mathematical, relational, conditional, or logical operations on data.

These are examples of assignment operators in programming. Assignment operators are used
to assign values to variables in a more concise manner than writing out the full assignment
statement.

Here's a breakdown of the operators and their corresponding examples:

1. `=` (Assignment operator): Assigns the value on the right-hand side to the variable on the left-
hand side.
Example: `x = 5` assigns the value `5` to the variable `x`.

2. `+=` (Addition assignment operator): Adds the value on the right-hand side to the variable on
the left-hand side.
Example: `x += 3` is equivalent to `x = x + 3`.

3. `-=` (Subtraction assignment operator): Subtracts the value on the right-hand side from the
variable on the left-hand side.
Example: `x -= 3` is equivalent to `x = x - 3`.

4. `*=` (Multiplication assignment operator): Multiplies the variable on the left-hand side by the
value on the right-hand side.
Example: `x *= 3` is equivalent to `x = x * 3`.

5. `/=` (Division assignment operator): Divides the variable on the left-hand side by the value on
the right-hand side.
Example: `x /= 3` is equivalent to `x = x / 3`.
6. `%=` (Modulus assignment operator): Assigns the remainder of dividing the variable on the
left-hand side by the value on the right-hand side.
Example: `x %= 3` is equivalent to `x = x % 3`.

7. `&=` (Bitwise AND assignment operator): Performs a bitwise AND operation between the
variable on the left-hand side and the value on the right-hand side, and assigns the result to the
variable on the left-hand side.
Example: `x &= 3` is equivalent to `x = x & 3`.

8. `|=` (Bitwise OR assignment operator): Performs a bitwise OR operation between the variable
on the left-hand side and the value on the right-hand side, and assigns the result to the variable
on the left-hand side.
Example: `x |= 3` is equivalent to `x = x | 3`.

9. `^=` (Bitwise XOR assignment operator): Performs a bitwise XOR operation between the
variable on the left-hand side and the value on the right-hand side, and assigns the result to the
variable on the left-hand side.
Example: `x ^= 3` is equivalent to `x = x ^ 3`.

10. `>>=` (Right shift assignment operator): Shifts the bits of the variable on the left-hand side to
the right by the number of positions specified by the value on the right-hand side, and assigns
the result to the variable on the left-hand side.
Example: `x >>= 3` is equivalent to `x = x >> 3`.

11. `<<=` (Left shift assignment operator): Shifts the bits of the variable on the left-hand side to
the left by the number of positions specified by the value on the right-hand side, and assigns the
result to the variable on the left-hand side.
Example: `x <<= 3` is equivalent to `x = x << 3`.

These assignment operators can be handy for making code more concise and readable,
especially when performing repetitive operations on variables.

--- NOTES FOR STUDENTS

- **C Language Basics:** C is a powerful and versatile programming language widely used in
various fields, including software development, system programming, and embedded systems.
- **Understanding Syntax:** Learning C involves understanding its syntax, including variables,
data types, operators, and basic input-output commands.
- **Practice and Experimentation:** To become proficient in C programming, practice coding
regularly and experiment with different concepts and techniques.
- **Online Resources:** Utilize online tutorials, forums, and resources to supplement your
learning and seek assistance when needed.
- **Start Simple:** Begin with simple programs and gradually tackle more complex tasks as you
gain confidence and proficiency in C programming.

You might also like