Syntax, Variables, Data Types, Constants, and Input Output
Learn the basic syntax of C programs, primitive data types, variable declarations, constants, formatting, and console input-output.
Inside this chapter
- Basic Syntax Rules
- Primitive Data Types
- Declaring Variables and Constants
- Formatted Output and Input
- Format Specifiers
- Real-World Usage Snapshot
Series navigation
Study the chapters in order for the clearest path from C basics to advanced memory, systems, debugging, and real-world development practice. Use the navigation at the bottom of each page to move smoothly through the full tutorial.
Basic Syntax Rules
C is case-sensitive. Statements usually end with semicolons. Blocks are defined using braces. Variables must be declared before use. Unlike some higher-level languages, C expects the programmer to be precise about types and storage.
Primitive Data Types
| Type | Typical Usage |
|---|---|
| int | Whole numbers |
| char | Single character or small integer byte value |
| float | Single-precision floating-point |
| double | Double-precision floating-point |
| long | Larger integer range depending on platform |
Type size can depend on platform and compiler, so students should focus first on meaning and usage, then later on exact memory-level implications.
Declaring Variables and Constants
int age = 21;
double price = 49.99;
char grade = 'A';
const int DAYS_IN_WEEK = 7;
const expresses intent clearly and helps prevent accidental modification.
Formatted Output and Input
#include <stdio.h>
int main(void) {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You entered: %d\n", age);
return 0;
}
printf and scanf are fundamental, but beginners must be careful with format specifiers and addresses. The & operator in scanf is one of the first hints that C deals directly with memory addresses.
Format Specifiers
%dforint%fforfloatanddoubleinprintf%cforchar%sfor strings%ldforlong
Real-World Usage Snapshot
Even experienced engineers working with advanced systems still rely on clear understanding of primitive types, input-output formatting, and type discipline. Bugs in these basics can lead to wrong calculations, crashes, or undefined behavior later.