C Language Basics
Structure of a C Program
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Key Components
#include <stdio.h>— Header file for input/output functionsint main()— Main function where program execution beginsprintf()— Function to print output to the screenreturn 0;— Indicates successful program execution
Variables & Data Types
int age = 15; // Integer
float marks = 85.5; // Floating point
char grade = 'A'; // Single character
Common Data Types
| Type | Size | Example |
|---|---|---|
int | 2/4 bytes | int a = 10; |
float | 4 bytes | float b = 5.5; |
char | 1 byte | char c = 'X'; |
Input & Output
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered: %d", num);
%d— Integer format specifier%f— Float format specifier%c— Character format specifier%s— String format specifier
Comments
// This is a single-line comment
/* This is a
multi-line comment */
Exam Tips
- Always include
stdio.hfor input/output functions main()function is mandatory in every C program- Use
&before variable name inscanf() - Every statement ends with a semicolon (
;)