C Programming – Unit 1 Concise Notes
1. Introduction to C Language
C is a general-purpose, structured programming language developed by Dennis Ritchie in 1972 at Bell Labs. It is
used to develop system software, operating systems, and applications due to its efficiency and flexibility. Features:
• Simple and powerful. • Portable (can run on different platforms). • Supports modular programming using
functions. • Provides low-level access to memory through pointers.
2. Structure of a C Program
A C program is divided into various sections: 1. Preprocessor Directives – Contains header files (e.g., #include ).
2. Global Declarations – Declare global variables and functions. 3. main() Function – Entry point of the program.
4. Variable Declarations and Statements – Logic and computation. Example: #include int main() { printf("Hello
World"); return 0; }
3. Pseudo Code
Pseudo code is a step-by-step description of an algorithm using simple language that resembles programming
syntax. Purpose: To plan the logic before writing the actual code. Example: Start Input two numbers A, B Sum =
A + B Print Sum End
4. Algorithm
An algorithm is a finite set of instructions to solve a problem or perform a computation. Characteristics: •
Finiteness – It must terminate. • Input/Output – Takes input and produces output. • Definiteness – Each step must
be clear. • Effectiveness – Steps must be feasible. Example (Sum of two numbers): Step 1: Start Step 2: Input A, B
Step 3: Sum = A + B Step 4: Print Sum Step 5: Stop
5. Flowchart
A flowchart is a graphical representation of an algorithm using symbols. Symbols: • Oval – Start/End •
Parallelogram – Input/Output • Rectangle – Process • Diamond – Decision Example: Flowchart for checking
even/odd number. Start → Input N → N%2==0? → Yes → Print “Even” → No → Print “Odd” → Stop
6. Tokens in C
Tokens are the smallest elements in a C program. Types of Tokens: 1. Keywords – Reserved words (int, if, return,
etc.). 2. Identifiers – Names given to variables or functions. 3. Constants – Fixed values (e.g., 10, 3.14, ‘A’). 4.
Strings – Sequence of characters ("Hello"). 5. Operators – Symbols for operations (+, -, *, /). 6. Special Symbols –
{}, (), [], ;, etc.
7. Operators in C
Operators perform operations on operands. Types: • Arithmetic (+, -, *, /, %) • Relational (==, !=, >, <, >=, <=) •
Logical (&&, ||, !) • Assignment (=, +=, -=) • Increment/Decrement (++ , --) • Conditional (?:) • Bitwise (&, |, ^,
<<, >>) Example: int a=5,b=3; printf("%d", a+b); // Output 8
8. Data Types
Define the type of data a variable can hold. Basic Data Types: • int – Integer values (2 or 4 bytes) • float – Decimal
numbers • char – Single character • double – Double precision float Derived Data Types: Arrays, Functions,
Pointers, Structures. Example: int a=10; float b=2.5;
9. Variables
Variables are named memory locations used to store data. Rules: • Must start with a letter or underscore. • No
special characters or spaces allowed. • Must be declared before use. Syntax: data_type variable_name; Example:
int age = 18;
10. Input and Output Statements
Used for data interaction between user and program. • printf() – To display output. Syntax: printf("Sum = %d",
sum); • scanf() – To take input from user. Syntax: scanf("%d", #); Example: int a,b; scanf("%d%d",&a;,&b;);
printf("Sum = %d", a+b);
11. Comments
Comments improve readability and are ignored by the compiler. • Single-line comment: // This is a comment •
Multi-line comment: /* This is a comment */ Example: /* Program to display Hello World */ printf("Hello
World");
12. Decision Making Statements
Used for conditional execution. • if Statement: if(condition) { statements; } • if-else Statement: if(condition) { true
block; } else { false block; } • Nested if: if inside another if. • else-if Ladder: if(cond1) { } else if(cond2) { } else {
} • goto Statement: Used to jump to another part of the program (avoid excessive use). Example: if(x>0)
printf("Positive"); else if(x<0) printf("Negative"); else printf("Zero");
13. Summary
C is a structured programming language that uses algorithms, flowcharts, and pseudo code to plan logic. Tokens,
operators, data types, and decision-making statements form the foundation of C programs. Understanding syntax,
structure, and control flow is essential for writing and debugging programs effectively.