7. Best Basic Practices and Style Guidelines
7.1 Naming Conventions
- Variables: Use descriptive names (
student_count
, notsc
) - Constants: Use uppercase (
MAX_SIZE
,PI
) - Functions (we will learn more about this in the next module): Use verb-noun pattern (
calculate_area
,print_result
)
7.2 Code Organization
#include <stdio.h> // System headers
#include <stdlib.h>
#define MAX_SIZE 100 // Constants
// Function prototypes (We will learn more about this in the next module)
int add(int a, int b);
void print_result(int result);
int main() {
// Main program logic
return 0;
}
// Function definitions (We will learn more about this in the next module)
int add(int a, int b) {
return a + b;
}
7.3 Error Handling
Input Validation:
int num;
printf("Enter a positive number: ");
scanf("%d", &num)
if (num <= 0) {
printf("Invalid input!\n");
}