Beginner Study Notes • Examples • Practice Exercises
Learning goal: Understand the basic building blocks of a C program and practice writing small, readable programs.
1. What Is C Programming?
C is a general-purpose, procedural programming language used in system software, embedded devices,
command-line tools, and performance-sensitive applications.
• A program is a set of instructions a computer follows.
• A compiler translates source code into a form the computer can run.
• C is case-sensitive: main and Main are different identifiers.
2. Your First C Program
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
• #include <stdio.h> provides the declaration for printf().
• main() is the entry point in a hosted C program.
• printf() prints text; \n starts a new line.
• return 0; conventionally reports success.
3. Variables and Data Types
Variables store values. Each variable has a type that determines what kind of value it can represent.
Type Example Meaning
int int age = 16; Integer value
float float price = 4.5f; Single-precision decimal
double double pi = 3.14159; Double-precision decimal
char char grade = 'A'; Character / small integer type
Initialize variables before using them. A local variable that has not been initialized may contain an indeterminate value.
4. Input and Output
int age;
printf("Enter your age: ");
if (scanf("%d", &age) == 1) {
printf("You entered %d\n", age);
}
scanf() reads formatted input. For an integer, %d is common. & supplies the variable's address. Checking the return
value helps detect invalid input.
5. Operators
• Arithmetic: + - * / %. With integers, gives 3.
Introduction to C Programming • Study Notes Page 1