C Programming Fundamentals: Variables & Data Types, Summaries of Computer science

An essential self-study module covering the absolute basics of C programming. Learn how variables store data, master foundational data types (int, float, double, char), and explore syntax rules using highly scannable tables, conceptual analogies, and ready-to-run code examples. Perfect for beginners looking to understand the "blueprint language" of modern computing.

Typology: Summaries

2021/2022

Available from 06/23/2026

raunak-bansal
raunak-bansal ๐Ÿ‡ฎ๐Ÿ‡ณ

2 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Basics of C Programming โ€” Self Study Notes
What is C?
C is one of the oldest and most powerful programming languages, created in the 1970s. Think of
C as the blueprint language โ€” almost every modern language (Python, Java, JavaScript)
borrowed ideas from it. Learning C is like learning to drive a manual car: harder at first, but you
understand how the engine works.
Variables โ€” Labelled Boxes in Your Brain
A variable is a named storage location in memory. Think of it like a labelled jar in your kitchen
โ€” the label is the variable name, and whatever is inside is its value.
int age = 25;
Jar analogy: The jar is labelled age. Inside it, you've placed the number 25. You can empty it
and refill it with a different number anytime.
Rules for naming variables:
โ€ข Must start with a letter or underscore (_)
โ€ข No spaces, use _ instead (e.g., student_name)
โ€ข Case-sensitive: Age and age are two different jars
Data Types โ€” The Type of Jar You Use
Not all jars are the same. You wouldn't store soup in a sugar dispenser. In C, data types tell the
computer what kind of value the variable will hold โ€” and how much memory to reserve.
1. int โ€” Whole Numbers
Real world: Number of students in a class, your age, a house number.
pf3
pf4

Partial preview of the text

Download C Programming Fundamentals: Variables & Data Types and more Summaries Computer science in PDF only on Docsity!

Basics of C Programming โ€” Self Study Notes What is C? C is one of the oldest and most powerful programming languages, created in the 1970s. Think of C as the blueprint language โ€” almost every modern language (Python, Java, JavaScript) borrowed ideas from it. Learning C is like learning to drive a manual car: harder at first, but you understand how the engine works. Variables โ€” Labelled Boxes in Your Brain A variable is a named storage location in memory. Think of it like a labelled jar in your kitchen โ€” the label is the variable name, and whatever is inside is its value. int age = 25; Jar analogy: The jar is labelled age. Inside it, you've placed the number 25. You can empty it and refill it with a different number anytime. Rules for naming variables:

  • Must start with a letter or underscore ( _ )
  • No spaces, use _ instead (e.g., student_name )
  • Case-sensitive: Age and age are two different jars Data Types โ€” The Type of Jar You Use Not all jars are the same. You wouldn't store soup in a sugar dispenser. In C, data types tell the computer what kind of value the variable will hold โ€” and how much memory to reserve. 1. int โ€” Whole Numbers Real world: Number of students in a class, your age, a house number.

int students = 42; int floors = 3; Imagine counting floors in a building โ€” you say 3, not 3.5. Memory used: 4 bytes (can hold roughly โˆ’2 billion to +2 billion)

2. float โ€” Decimal Numbers (Single Precision) Real world: Price of groceries, your temperature reading, a petrol bill. float price = 89.99; float temperature = 36.6; A thermometer shows 36.6ยฐC โ€” not just 36. That decimal matters. Memory used: 4 bytes (~6โ€“7 decimal digits of precision) 3. double โ€” Decimal Numbers (High Precision) Real world: Scientific calculations, GPS coordinates, bank balances. double distance = 384400.756; // Distance to the Moon in km double balance = 1000250.8875; When NASA calculates a rocket's path, they can't round off. Every decimal counts. Memory used: 8 bytes (~15 decimal digits of precision) 4. char โ€” A Single Character Real world: A grade on your report card, a gender field (M/F), a single letter in a word. char grade = 'A'; char initial = 'R';

This is like a student's profile card โ€” age, marks, fees, and grade all stored neatly in their own labelled compartment. Quick Reference Table Data Type Real World Example Format Specifier Size int Number of chairs %d 4 bytes float Petrol price %f 4 bytes double Bank account balance %lf 8 bytes char Blood group (A, B) %c 1 byte Key Takeaways

  • A variable is a named container โ€” pick names that describe what's inside
  • Choose the right data type for the right job โ€” don't use a double when an int will do
  • C is case-sensitive โ€” Score and score are completely different variables
  • Every C program starts with main() and needs #include to print output