C Language

C Language

C is a general-purpose programming language that was developed in the early 1970s by Dennis Ritchie at Bell Labs. It is one of the most important and influential programming languages, widely used for system programming, embedded systems, and application development.


🔹 Key Features of C

  • Simple and Efficient: Provides low-level access to memory, making programs fast.
  • Structured Language: Supports functions, loops, and conditionals for organized code.
  • Portable: Programs written in C can run on different machines with little modification.
  • Middle-Level Language: Combines features of both high-level and low-level languages.
  • Rich Library: Includes built-in functions for input/output, string handling, etc.

🔹 Basic Structure of a C Program

A simple C program looks like this:

 

#include <stdio.h> // Header file

int main() { // Main function
printf(“Hello, World!”); // Output statement
return 0; // Exit program
}

 

Explanation:

  • #include <stdio.h> → Includes standard input/output functions.
  • int main() → Entry point of the program.
  • printf() → Prints output to the screen.
  • return 0; → Ends the program successfully.

🔹 Basic Concepts in C

1. Variables and Data Types

Variables store data. Common types:

  • int → Integer values (e.g., 10)
  • float → Decimal values (e.g., 3.14)
  • char → Characters (e.g., ‘A’)

Example:

 
int age = 20;
float pi = 3.14;
char grade = ‘A’;
 

2. Operators

Used to perform operations:

  • Arithmetic: + - * / %
  • Relational: == != > <
  • Logical: && || !

3. Control Statements

Control the flow of execution:

  • if-else
  • switch
  • loops: for, while, do-while

Example:

 
if (age > 18) {
printf(“Adult”);
} else {
printf(“Minor”);
}
 

4. Functions

Reusable blocks of code:

 
int add(int a, int b) {
return a + b;
}
 

5. Arrays

Store multiple values of the same type:

 
int numbers[5] = {1, 2, 3, 4, 5};
 

6. Pointers

Special feature of C that stores memory addresses:

 
int x = 10;
int *ptr = &x;
 

🔹 Uses of C

  • Operating systems (e.g., Unix)
  • Embedded systems (microcontrollers)
  • Game development
  • Compilers and interpreters

🔹 Advantages

  • Fast execution
  • Close to hardware
  • Flexible and powerful

🔹 Disadvantages

  • No built-in garbage collection
  • Manual memory management
  • Less secure compared to modern languages

Leave a Reply

Your email address will not be published. Required fields are marked *