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

  1. Simple and Efficient: Provides low-level access to memory.
  2. Portable: Programs written on one computer can run on another with little or no modification.
  3. Structured: Supports modular programming using functions.
  4. Case Sensitive: printf and Printf are different.
  5. Fixed number of Keywords: Only 32 keywords.

3.3 Structure of a C Program

A typical C program has the following sections:

  1. Documentation Section: Comments explaining the program.
  2. Link Section: Header files like #include <stdio.h>.
  3. Definition Section: Defining symbolic constants using #define.
  4. Global Declaration Section: Declaring variables used globally.
  5. Main Function Section: Every C program execution starts from main().
  6. 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 the main() 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.

NEXT
Problem Solving using Computer