CodeToLive

Introduction to C

C is a general-purpose, procedural programming language developed by Dennis Ritchie in 1972. It is widely used for system programming, embedded systems, and developing operating systems. C is known for its efficiency and low-level memory manipulation capabilities.

Key Features of C:

Why Learn C?

Learning C is essential for understanding the fundamentals of programming and computer science. It is the foundation for many modern programming languages like C++, Java, and Python. C is also widely used in:

Basic Structure of a C Program

A C program typically consists of the following components:


// Preprocessor Directives
#include <stdio.h>

// Main Function
int main() {
    // Program Statements
    printf("Hello, World!\n");
    return 0; // Return Statement
}
      

Example: Hello World in C


// C Hello World Program
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
      

This program includes the standard input-output library (stdio.h) and uses the printf function to print "Hello, World!" to the console.

Compiling and Running a C Program

To compile and run a C program, follow these steps:

  1. Write the program in a text editor and save it with a .c extension (e.g., hello.c).
  2. Open a terminal or command prompt and navigate to the directory containing the program.
  3. Compile the program using a C compiler like gcc:
    
    gcc hello.c -o hello
          
  4. Run the compiled program:
    
    ./hello
          

Common C Libraries

C provides a rich set of standard libraries for various tasks. Some commonly used libraries include:

Next: Variables and Data Types