PROGRAMMING IN C – CHAPTER-WISE NOTES (BSc CS)
============================================== UNIT 1: INTRODUCTION TO C
============================================== - C developed by Dennis
Ritchie (1972, Bell Labs). - Features: Fast, portable, procedural,
middle-level language. - Structure of C Program: #include <stdio.h> int
main() { …statements… return 0; } - Tokens: keywords, identifiers,
constants, operators, strings. - Data Types: int, float, char, double,
void. - Variables: Memory name that stores value. - Constants: Cannot be
changed during execution. - Input/Output: printf(“text”); scanf(“%d”,
&var);
============================================== UNIT 2: OPERATORS &
EXPRESSIONS ============================================== -
Arithmetic: + - * / % - Relational: > < >= <= == != - Logical: && || ! -
Assignment: = += -= *= - Bitwise: & | ^ << >> - Conditional: (condition
? true : false) - Operator precedence determines evaluation order.
============================================== UNIT 3: CONTROL
STATEMENTS ============================================== Conditional: -
if - if-else - else-if ladder - nested if - switch-case
Loops: - for loop: for(init; condition; inc) - while loop - do-while
loop
Jump Statements: - break - continue - goto
============================================== UNIT 4: FUNCTIONS
============================================== - Function = block of
code that performs a task. Syntax: return_type name(parameters){ // code
}
- Types:
- User-defined
- Built-in (library)
- Function calling methods:
- Call by Value
- Call by Reference
- Recursion: Function calling itself.
- Storage Classes: auto, static, extern, register.
============================================== UNIT 5: ARRAYS
============================================== - Array stores multiple
values of same type. - 1D Array: int a[5]; - 2D Array: int b[3][3]; -
Multi-dimensional arrays. - Passing arrays to functions.
============================================== UNIT 6: STRINGS
============================================== - String = array of
characters. - Example: char name[20] = “ABC”; - String functions:
strlen() strcpy() strcat() strcmp() - Array of strings.
============================================== UNIT 7: POINTERS
============================================== - Pointer stores address
of variable. Example: int *p; p = &x;
- Pointer arithmetic: p++, p–.
- Pointers and arrays.
- Pointers to functions and pointers to pointers.
============================================== UNIT 8: STRUCTURES &
UNIONS ============================================== Structure: struct
student { int id; char name[20]; float marks; };
- Access: [Link], [Link]
- Array of structures.
- Nested structures.
Union: - Shares memory among all members.
============================================== UNIT 9: FILE HANDLING
============================================== - File operations:
fopen() fclose() fputc() fgetc() fprintf() fscanf()
Modes: r – read w – write a – append r+, w+, a+ – read/write
============================================== UNIT 10: DYNAMIC MEMORY
ALLOCATION ============================================== -
malloc(size) - calloc(n, size) - realloc(ptr, size) - free(ptr)
============================================== UNIT 11: PREPROCESSOR
DIRECTIVES ============================================== - #include -
#define - Macros - Header files - Conditional compilation (#ifdef,
#ifndef)
============================================== END OF NOTES
==============================================