UNIT I - CY - C
UNIT-1: Programming in C
Page 1
Title: UNIT-1 PROGRAMMING IN C
Course: BSc CS with CY
Instructor: NEETHU DS
Page 2: HISTORY OF COMPUTERS
Introduction
The term "computer" is derived from "compute".
Definition of a Computer
A computer is an electronic device that accepts data and instructions as input, processes this data, and produces useful information as output.
Input-Process-Output Cycle
The cycle of operation of a computer is:
Input
Process
Output
Advantages of Computers:
High Speed
Accuracy
Storage Capability
Diligence (works continuously until reaching the expected result)
Versatility (flexible)
Reliability (trustworthy)
Automation (computerization)
Reduction in Paperwork and Cost
Disadvantages of Computers:
No intelligence (I.Q.)
Dependency on machines
Environmental impact
Lack of feelings
Applications of Computers:
Business
Banking
Insurance
Education
Marketing (Advertising, Home Shopping)
Healthcare (various systems)
Engineering Design
Military (various operations)
Communication (various mediums)
Government (services)
Page 3: Hardware Components
Components of Hardware:
Input Devices
Output Devices
Processor
Memory
Input Devices:
Devices that help enter data into the computer (e.g., keyboard, mouse, scanner).
Output Devices:
Devices that present processed data to the user (e.g., monitor, printer, speakers).
Processor (CPU):
The brain of the computer that performs calculations and processes data.
Consists of:
Arithmetic Logic Unit (ALU)
Control Unit (CU)
Memory:
Consists of primary (RAM) and secondary memory (hard disks, floppy disks).
Page 4: Computer Algorithms
Basic of Algorithms:
An algorithm is a step-by-step set of instructions that defines how to perform a task.
For example, a recipe follows a specific order to yield the desired dish.
Characteristics of an Algorithm:
Clear and unambiguous
Well-defined inputs & outputs
Finite-ness
Feasibility
Language independence
Advantages of Algorithms:
Easy to understand
Step-wise representation of solutions
Disadvantages of Algorithms:
Time-consuming to write
Difficulties in expressing branching and looping
Designing an Algorithm:
Define the problem to solve
Consider constraints
List expected inputs and outputs
Write the steps to solve the problem, e.g., adding three numbers.
Page 5: Testing Algorithms
Types of Analysis:
Priori Analysis: Evaluate the algorithm before implementation, checking its theoretical steps.
Posterior Analysis: Evaluate the algorithm after implementation, checking for correctness, space, and time considerations.
Time and Space Complexity:
Time Complexity: Measures execution time based on operations performed.
Space Complexity: Measures the memory required.
Page 6: History of C
The C programming language emerged in the 1970s from Bell Labs for Unix operating system implementation.
Created by Dennis Ritchie as a derivative of "B" language developed by Ken Thompson.
Formal Standardization:
The first standard was ratified as ANSI X3.159-1989.
Pages 7-8: Uses of C Today
Commonly used in UNIX and systems programming.
Underpins many databases like Oracle and MySQL.
Forms the basis for C++ and other languages.
Page 9: C Character Set
The character set includes all valid characters for programming in C, comprising digits, alphabets, and special symbols, totaling about 256 characters supported.
Types of Characters:
Digits: 0-9
Alphabets: A-Z, a-z
Special Characters: Used for operations and conditions.
Pages 10-11: Tokens in C
Definition:
Tokens are the smallest individual elements, such as keywords, identifiers, strings, operators, constants, and special characters.
Keywords:
Predefined reserved words with specific functions (e.g., int, char, float). Only 32 keywords exist in C.
Identifiers:
User-defined names for variables, functions, etc. Must start with a letter or underscore and can include numbers. They are case sensitive.
Pages 12-13: Special Characters in C
Special characters serve various programming purposes, such as defining arrays and operations.
Page 14: Strings in C
Strings in C are arrays of characters ending with a null character '\0'.
Page 15-16: Operators in C
Classification:
Unary Operators: Operate on one operand (e.g., increment, decrement).
Binary Operators: Operate on two operands (e.g., arithmetic, relational).
Operator Precedence:
Order of operations defined for expressions, e.g., multiplication before addition.
Page 17-18: Arithmetic Operators
Perform basic numerical operations:
Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (%)
Page 19-20: Examples of Arithmetic Expressions
Integer and Floating-point Arithmetic explained with examples based on basic operations.
Page 21-24: Relational Operators
Used for comparisons between values. Examples include less than (<), greater than (>), and equal to (==).
Pages 25-28: Logical Operators
Evaluate logical expressions with conditions. They include Logical AND (&&), OR (||), and NOT (!).
Page 29-30: Increment and Decrement Operators
Precedes or succeeds a variable to modify its value (+1 or -1). Examples include prefix and postfix variations.
Page 31-33: Assignment Operators
Used to assign values to variables. Examples include standard assignment (=) and compound assignments (+=, -=).
Pages 34-38: Precedence of Operators and Examples
Illustrated how operator precedence affects expression evaluation, using triangle models and tables.
Pages 39-40: Conclusion on Operators
Summarized different operator categories including arithmetic, relational, and logical.
Page 41-44: Practical Examples and Programs in C
Provided C code for practical applications of operators, showcasing assignments and operations.