1. The Main Function
The main function serves as the antry point for all C programs. Every C program must contain exactly one main function.
#include <stdio.h>
int main(void) // Standard compliant declaration
{
printf("Welcome to C programming\n");
return 0; // Indicates successful execution
}
Common variations of main function declarations:
int main() { ... }
int main(void) { ... }
2. Output Functions
The printf function displays formatted output to the standard output device:
#include <stdio.h>
int main()
{
printf("Displaying formatted output\n");
printf("Integer: %d, Character: %c\n", 42, 'A');
return 0;
}
3. Standard Library Functions
C provides numerous built-in functions through standard libraries. These require appropriate header files:
#include <math.h> // Math functions
#include <string.h> // String operations
4. Reserved Keywords
C language defines 32 reserved keywords that cannot be used as identifiers:
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
5. Character Encoding
C uses ASCII encoding for character representation:
printf("ASCII code for 'A': %d\n", 'A'); // Outputs 65
printf("Character for 97: %c\n", 97); // Outputs 'a'
6. String Handling
Strings in C are null-terimnated character arrays:
char message[] = "Hello"; // Actually stores 'H','e','l','l','o','\0'
printf("%s\n", message); // Prints until null character
7. Escape Sequences
Special character combinations for formatting:
printf("New\nLine\tTab\\Backslash\n");
printf("Alert\aBeep\bBackspace\rCarriageReturn");
8. Statement Types
C programs consist of several statement types:
- Expression statements (a = b + c;)
- Function calls (printf(...);)
- Control flow (if, for, while)
- Compound statements ({...})
9. Code Documentation
C supports two comment styles:
/* Multi-line comment
spanning several lines */
// Single-line comment
int x = 5; // End-of-line comment