Introduction to C Programming (Lesson)
Introduction to C Programming
C is a powerful general-purpose programming language. It has been used to develop operating systems, databases, compilers, and so on.
3.1 History of C
- Developed by: Dennis Ritchie
- Year: 1972
- Place: AT&T Bell Laboratories (USA)
- Purpose: To develop the UNIX operating system.
- Predecessors: It was evolved from B and BCPL languages.
3.2 Key Features of C
- Simple and Efficient: Provides low-level access to memory.
- Portable: Programs written on one computer can run on another with little or no modification.
- Structured: Supports modular programming using functions.
- Case Sensitive:
printfandPrintfare different. - Fixed number of Keywords: Only 32 keywords.
3.3 Structure of a C Program
A typical C program has the following sections:
- Documentation Section: Comments explaining the program.
- Link Section: Header files like
#include <stdio.h>. - Definition Section: Defining symbolic constants using
#define. - Global Declaration Section: Declaring variables used globally.
- Main Function Section: Every C program execution starts from
main(). - Subprogram Section: User-defined functions.
3.4 Your First C Program: Hello World
Let's look at the simplest C program:
/* Documentation: This program prints Hello World */
#include <stdio.h> // Link Section
int main() { // Main Function
printf("Hello, world!\n"); // Executable Statement
return 0; // Return Statement
}
Explanation:
#include <stdio.h>: This is a preprocessor command that tells the compiler to include the Standard Input/Output library.int main(): This is the entry point of the program. Execution always starts here.{ }: The curly braces mark the beginning and end of a block of code.printf(): A function used to print text on the screen.\n: Represents a new line.return 0: Terminates themain()function and returns a 0 value to the operating system, signifying successful execution.
Refer to the Lecture Slides for a "Deep Dive" into the main() function properties.