What is C?

Introduction

C is a general-purpose programming language originally developed at Bell Labs in the 1970s. It was designed by Dennis Ritchie for system programming, but it's widely used in various application domains.

Key Features

  • Procedural Language: C is a procedural programming language, which means it follows a top-down approach in program design.
  • Low-Level: C provides a high degree of control over hardware, making it suitable for system programming and embedded systems.
  • Portability: Code written in C can be compiled for different platforms with minimal changes, thanks to its portability.
  • Efficiency: C is known for its efficiency and is often used for performance-critical applications.
  • Syntax: C has a simple and elegant syntax. It uses a combination of keywords and punctuation, making it highly readable and expressive.
  • Standard Libraries: C comes with a standard library that provides functions and macros for performing various tasks, from I/O operations to mathematical calculations.

Applications

  • Operating Systems: Many operating systems are written in C or have components written in C (e.g., Unix, Linux).
  • Embedded Systems: C is prevalent in embedded systems like microcontrollers and IoT devices.
  • Game Development: It's used for game development, especially in writing game engines.
  • Compiler Development: C is often used to develop compilers and interpreters for other languages.

Example: Hello World program in C


  #include

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

Popularity

C has a strong legacy and is still widely used in industry and education due to its powerful features and low-level capabilities.

Getting Started with C

The C Character Set

C Character Set: C uses a character set that consists of letters, digits, and various special characters. It's essential to understand this character set when writing C code.

Character Set Components:

  • Letters: Uppercase and lowercase letters are distinct in C.
  • Digits: C uses decimal digits (0-9).
  • Special Characters: Special characters like +, -, *, /, %, &, |, !, etc., are used for operations.

Constants, Variables, and Keywords

Constants:

Constants in C are values that do not change during program execution. They can be of different types, including integer constants (e.g., 42), floating-point constants (e.g., 3.14), and character constants (e.g., 'A').

Variables:

Variables are used to store data that can change during program execution. You must declare variables with a data type before using them.

Data Types:

C supports various data types, including:

  • int: For integers.
  • float: For floating-point numbers.
  • char: For characters.
  • double: For double-precision floating-point numbers.

Keywords:

Keywords are reserved words in C and cannot be used as identifiers (variable or function names). Examples include "int," "if," "while," "return," and "break."

Example:


#include 

int main() {
    int age;  // Declaration of an integer variable
    age = 30; // Assignment of a value to the variable
     printf("My age is %d years.\n", age);
  return 0;
}
        

Note: C is case-sensitive, so "Age" and "age" would be treated as different variables.