C Programming in One Shot | Part 1 Notes
1. Introduction & Prerequisites
Target Audience: First-year students, placement/test aspirants, and absolute beginners in
coding.
Requirements: Laptop/PC (any configuration); optional phone for side-by-side coding;
basic 10th-grade mathematics comfort.
Tools: Online C compiler (e.g., Online GDB) initially; transition to Visual Studio Code for
offline work.
2. “Hello, World!” & Output in C
Basic Program Structure
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
printf Function
Prints exactly what’s inside double quotes to the output screen.
Requires #include <stdio.h> header to avoid compiler warnings.
3. Escape Sequences
New Line (\n)
Inserts a line break without printing the sequence itself.
Multiple \n give multiple blank lines.
Examples
printf("Line 1\nLine 2\n");
prints:
Line 1
Line 2
4. Variables & Data Types
Concept: Containers to hold values in memory.
Declaration Syntax:
int x;
float radius;
char grade;
Common Types
int (integer)
float/double (floating-point)
char (single character)
5. Input in C
scanf Function
Reads values from user and stores them in variables.
Format specifier must match variable type.
int a;
scanf("%d", &a);
6. Operators & Expressions
Arithmetic Operators: +, -, *, /, %
Operator Precedence:
1. Parentheses ()
2. Multiplication/Division/Modulo
3. Addition/Subtraction
Example
float result = (a + b) * c / d;
7. Sample Problems
1. Volume of a Sphere
float r;
scanf("%f", &r);
float volume = 4.0/3.0 * 3.14159 * r * r * r;
printf("Volume: %.2f", volume);
2. Percentage of 5 Subjects
int m1, m2, m3, m4, m5;
scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);
float percentage = (m1 + m2 + m3 + m4 + m5) / 5.0;
printf("Percentage: %.2f%%", percentage);
3. Simple Interest
float P, R, T;
scanf("%f %f %f", &P, &R, &T);
float SI = (P * R * T) / 100;
printf("Simple Interest: %.2f", SI);
8. Character Data Type & ASCII
char holds a single character.
ASCII Values: Each char maps to an integer code (e.g., 'A' = 65).
9. Variable Naming Rules
Must start with a letter or underscore (_).
Can contain letters, digits, and underscores.
Case-sensitive.
No spaces or special symbols.
10. Predict the Output Questions
Trace printf calls and escape sequences step by step.
Escape sequences (e.g., \n) don’t print literally; they change formatting.
11. Additional Topics (Preview)
Control Statements (if, for, while) – covered next lecture.
Short/Long Data Types, further MCQs.
Use this structure to review each section, write down key code snippets, test examples
yourself in an online compiler, and practice “predict the output” problems by dry-running
code.
⁂