DEV Community

Cover image for Introduction to C:)
Madhav Ganesan
Madhav Ganesan

Posted on • Originally published at madhavganesan.hashnode.dev

Introduction to C:)

History:

It was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A. It was developed after B,BCPL etc to overcome problems in that language. It was developed along with the UNIX operating system, and is strongly linked with UNIX operating system.

Image description

Paradigms:

Procedural Programming

#include <stdio.h>

void greet() {
    printf("Hello, World!\n");
}

int main() {
    greet();
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Low-level Programming

#include <stdio.h>

int main() {
    int x = 10;
    int *p = &x;
    printf("Value of x: %d\n", *p);
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Performance

C is a compiled language. The source code written in C is compiled into machine code by a compiler. This machine code is platform-specific and can be executed directly by the computer's hardware, leading to high performance and efficiency.

How to Run a C File

1) Open Notepad and Type C Code: Write your C code in a text editor.
2) Save the File with a .c Extension: Save your file with a .c extension.
3) Run the Following Commands:

gcc filename.c -o outputname // Compilation
./outputname // Execution
Enter fullscreen mode Exit fullscreen mode

Type System

Static Typing: Types are checked at compile-time, ensuring that type errors are caught early.

Strong Typing: Strict type rules are enforced, preventing type mismatches.

Manual Type Checking: The programmer is responsible for ensuring type correctness.

Abstraction

Low-Level Abstraction: C provides a low-level abstraction of the hardware, giving the programmer control over system resources and memory.

Important Facts

Manual Memory Management: C requires the programmer to manually allocate and deallocate memory using malloc, calloc, and free.
No Built-In Garbage Collection: C does not support automatic garbage collection, so memory management is the programmer's responsibility.

Usage

System Programming: Widely used for developing operating systems, compilers, and other system-level software.

Embedded Systems: Commonly used in the development of firmware and embedded software for devices such as microcontrollers and embedded systems.

Application Development: Used for developing performance-critical applications, such as video games and real-time systems.
Hardware Interface: Used to write drivers and interface with hardware components directly.

Scientific Computing: Utilized in scientific and engineering applications that require high performance.

Top comments (0)