Chapters
- Unit 1: Database Management System (DBMS) (12 Hours)
- Unit 2: Data Communication and Networking (15 Hours)
- Unit 3: Web Technology II (12 Hours)
- Unit 4: Programming in C (12 Hours)
- Unit 5: Object-Oriented Programming (OOP) (10 Hours)
- Unit 6: Software Process Model (10 Hours)
- Unit 7: Recent Trends in Technology (9 Hours)
Unit 4: Programming in C (12 Hours)
4.1 Review of C Programming Concepts
C is a foundational programming language that provides control over hardware and system resources. Key concepts include:
- Basic Structure: A typical C program consists of:
- Preprocessor directives (e.g.,
#include <stdio.h>
) - The
main()
function, which is the entry point of the program. - Variable declarations and function calls.
- Preprocessor directives (e.g.,
- Data Types: Fundamental types include:
int
,float
,char
,double
, etc.
- Control Structures: Decision-making (if, switch) and looping (for, while, do-while) structures control the flow of execution.
- Syntax and Semantics: Correct syntax is crucial for successful compilation and execution.
4.2 Functions
Functions are blocks of code designed to perform specific tasks, promoting code reuse and modularity.
4.2.1 Concept of Library and User-Defined Functions and Advantages
- Library Functions: Predefined functions in C libraries (like
printf()
,scanf()
) that can be used directly without definition. - User-Defined Functions: Functions created by the programmer to perform specific tasks.
- Advantages:
- Code Reusability: Functions can be reused in different programs.
- Easier Maintenance: Changes can be made in one place without affecting the whole code.
- Improved Readability: Programs become easier to understand.
- Advantages:
4.2.2 Function Definition, Prototype, Call, and Return Statements
- Function Definition: Specifies the function's return type, name, parameters, and body.
- Function Prototype: Declaration of a function that informs the compiler about its name, return type, and parameters before its actual definition.
- Function Call: The process of invoking a function using its name and passing arguments.
- Return Statement: Used to exit a function and optionally send a value back to the calling function.
4.2.3 Accessing a Function by Passing Values
Functions can access and manipulate data passed to them:
- Call by Value: A copy of the actual parameter is passed, leaving the original variable unchanged.
- Call by Reference: A reference (address) of the actual parameter is passed, allowing modifications to the original variable.
4.2.4 Concept of Storage: Automatic and External
- Automatic Storage: Local variables declared within functions are automatically allocated and deallocated. Their storage duration is tied to the function call.
- External Storage: Global variables, declared outside functions, have a lifetime equal to the program's execution. They retain their values throughout.
4.2.5 Concept of Recursion: Factorial and Fibonacci Problems
Recursion is a programming technique where a function calls itself to solve a problem.
- Base Case: The condition under which recursion terminates.
- Recursive Case: The part of the function where the function continues to call itself.
- Example: Factorial:
- Example: Fibonacci:
4.3 Structures and Unions
Structures and unions are user-defined data types that allow grouping related variables.
4.3.1 Structure: Definition, Declaration, Initialization, and Size of Structure
- Definition: A structure groups different data types under a single name.
- Declaration: Creating a structure variable.
- Initialization: Assigning values to a structure.
- Size of Structure: The size can be determined using the
sizeof
operator.
4.3.2 Accessing Member of Structure
Structure members are accessed using the dot operator (.
).
4.3.3 Array of Structure
An array can be created to store multiple structures.
4.3.4 Union: Definition, Declaration
- Definition: A union allows storing different data types in the same memory location. Only one member can store a value at a time.
- Declaration: Creating a union variable.
4.3.5 Difference Between Union and Structure
- Memory Allocation:
- Structure: Allocates memory for all members.
- Union: Allocates memory for the largest member only.
- Access:
- Structure: All members can be accessed simultaneously.
- Union: Only one member can be accessed at a time.
4.4 Pointers
Pointers are variables that store memory addresses, allowing for dynamic memory management.
4.4.1 Definition of Pointer
A pointer is declared using the asterisk (*
) symbol.
4.4.2 Address (&
) and Indirection (*
) Operator
- Address Operator (
&
): Used to get the address of a variable. - Indirection Operator (
*
): Used to access the value at the address stored in a pointer.
4.4.3 Pointer Expression and Assignment
Pointers can be used in expressions and can be assigned to other pointers.
4.4.4 Call by Value and Call by Reference
- Call by Value: A copy of the variable is passed.
- Call by Reference: The address of the variable is passed, allowing modifications to the original variable.
4.5 Working with Files
C provides functions to perform operations on files, allowing data to be saved and retrieved.
4.5.1 Concept of Data File
A data file is used for storing data that can be read and written by a program.
4.5.2 Sequential and Random File
- Sequential File: Data is accessed in a linear sequence.
- Random File: Data can be accessed in any order.
4.5.3 File Manipulation Functions
putw()
: Writes an integer to a file.getw()
: Reads an integer from a file.putc()
: Writes a character to a file.getc()
: Reads a character from a file.fscanf()
: Reads formatted data from a file.fprintf()
: Writes formatted data to a file.
4.5.4 Opening, Reading, Writing, and Appending Data File
- Opening a File: Use
fopen()
with modes like"r"
(read),"w"
(write), and"a"
(append). - Reading Data: Use functions like
fscanf()
orfgets()
to read data. - Writing Data: Use
fprintf()
orfputs()
to write data to a file. - Appending Data: Open the file in append mode (
"a"
) to add data without overwriting.