Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Fundamentals of C Programming Language

Tech 1

Compilation Process in Linux C

C Compilers

  • GNU GCC
  • Microsoft Visual C++ (MSVC)
  • Apple Clang
  • Intel C++ Compiler
  • Default Linux compiler: cc

Programming Language Classification

Compiled Languages (C, C++, Java)

  • Convert source code to machine instructions
  • Perform type safety checks
  • High performance
  • Less flexible

Interpreted Languages (Python, JavaScript, Java)

  • Execute source code directly in interpreter
  • High flexibility and expressiveness
  • Easier to learn
  • Lower performance

Compilation Steps

C source files:

  • .h header files: Contain declarations
  • .c source files: Contain implementations

Example compilation command:

gcc hello.c -o hello

Breeakdown of compilation process:

  1. Preprocessing & Assembly
    gcc -S hello.c -o hello.s
    
  2. Compilation to Object File
    gcc -c hello.s -o hello.o
    
  3. Linking
    gcc hello.o ... -o hello
    

C Language Basics

Variables and Types

// Variable declaration
int count;
double price;

// Constants
const int MAX_VALUE = 100;

Type System

  • Integer types: short, int, long, long long
  • Floating-point: float, double
  • Character: char
  • Boolean: bool

Operators

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

Control Structures

Conditional Statements

if (condition) {
    // code block
} else if (condition) {
    // code block
} else {
    // code block
}

switch (variable) {
    case value1:
        // code
        break;
    default:
        // code
}

Loops

// For loop
for (int i = 0; i < 10; i++) {
    // code
}

// While loop
while (condition) {
    // code
}

// Do-while loop
do {
    // code
} while (condition);

Functions

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

Pointers

int num = 10;
int *ptr = &num;
printf("Value: %d", *ptr);

Strings

char str[] = "Hello";
char *ptr = "World";

Structures

struct Point {
    int x;
    int y;
};

struct Point p1 = {10, 20};

Memory Management

// Dynamic allocation
int *arr = malloc(10 * sizeof(int));

// Release memory
free(arr);

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.