Topic: Basics of programming environment: editors, debuggers, translators, basics of program design and execution
Course: C Programming Fundamentals
Prepared by: Dr. Mohsin F. Dar
Designation: Assistant Professor, School of Computer Science
Institution: UPES, Dehradun
Target Audience: B.Tech-CSE-I-B47 and B.Tech-CSE-I-B48
A debugger is a tool that helps programmers find and fix errors (bugs) in their code by allowing them to:
gcc -g program.c -o program # Compile with debug info gdb ./program # Start debugger (gdb) break main # Set breakpoint at main (gdb) run # Run program (gdb) step # Execute one line (gdb) print variable_name # Print variable value (gdb) continue # Continue execution (gdb) quit # Exit debugger
A compiler is a translator that converts human-readable C source code into machine-executable binary code.
gcc hello.c # Compile to a.out (default) gcc hello.c -o hello # Compile to specific name gcc -Wall hello.c # Enable all warnings gcc -g hello.c # Include debug information gcc -O2 hello.c # Optimize for speed gcc -std=c99 hello.c # Use C99 standard
/* Header files and preprocessor directives */
#include <stdio.h>
#include <stdlib.h>
/* Global variable declarations (if needed) */
int global_counter = 0;
/* Function prototypes */
int add_numbers(int a, int b);
void print_result(int result);
/* Main function - program entry point */
int main() {
// Local variable declarations
int num1, num2, sum;
// Program logic
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
sum = add_numbers(num1, num2);
print_result(sum);
return 0; // Success indicator
}
/* Function definitions */
int add_numbers(int a, int b) {
return a + b;
}
void print_result(int result) {
printf("Result: %d\n", result);
}
Remember: A good programming environment and solid design principles are the foundation of successful C programming. Master these basics before moving to advanced topics!