PROGRAMMING IN C – NOTES (BSc CS 1st Year)
1) INTRODUCTION TO C
- C is a procedural, structured, general–purpose programming language.
- Developed by Dennis Ritchie in 1972 at Bell Labs.
- Used in system software, operating systems, embedded systems.
Characteristics: - Fast and efficient - Portable - Middle-level
language - Rich library support
2) STRUCTURE OF A C PROGRAM Basic structure: #include <stdio.h>
int main() { // statements return 0; }
Parts: - Header files - Main function - Body of program - Return
statement
3) DATA TYPES IN C Primary Data Types:
- int
- float
- char
- double
Derived Data Types: - arrays - pointers - structures - unions
4) VARIABLES AND CONSTANTS Variable: A name given to a memory location.
Example: int age;
Constants: Types: - Integer constant - Float constant - Character
constant - String constant
5) OPERATORS IN C Arithmetic: + - * / % Relational: > < >= <= == !=
Logical: && || ! Assignment: = += -= Increment/Decrement: ++ –
6) CONTROL STATEMENTS Conditional:
- if
- if-else
- else-if ladder
- switch
Looping: - for - while - do…while
Jump statements: - break - continue - goto
7) FUNCTIONS Function syntax: return_type function_name(parameters) {
// code }
Types: - Built-in functions - User-defined functions
Call by Value vs Call by Reference
8) ARRAYS Definition: Collection of similar data items.
1D Array Example: int a[5];
2D Array Example: int matrix[3][3];
9) STRINGS String = array of characters. Example: char name[20] =
“Computer”;
Common functions: strlen(), strcpy(), strcat(), strcmp()
10) POINTERS Pointer: Variable that stores address of another variable.
Example: int *ptr; ptr = &x;
Pointer arithmetic: ptr++ ptr–
11) STRUCTURES Used to store different data types together. Example:
struct student { int id; char name[20]; float marks; };
12) FILE HANDLING Main functions:
- fopen()
- fclose()
- fprintf()
- fscanf()
- fgetc()
- fputc()
Modes: r – read w – write a – append r+ / w+ / a+
END OF NOTES