C

C

Administrator

Thread Starter
LV
0
 
well-known master
Jan
88
1
Credits
3,050
Points
436
Staff member
Owner
The C language was developed between 1969-1973 at Bell Labs (now Nokia Bell Labs) by Dennis Ritchie. It was originally created to develop the UNIX operating system running on DEC PDP-11 computers. C evolved from the B language created by Ken Thompson, which in turn was inspired by BCPL.
C became extremely popular because of:
  1. Its high portability
  2. Its ability to access hardware-level features
  3. Its efficiency approaching assembly language
  4. Its structured yet flexible architecture
In 1978, Brian Kernighan and Dennis Ritchie published "The C Programming Language" book which became the de facto standard (known as "K&R C") until the ANSI C standard was released in 1989.

Dennis Ritchie - Creator of C​

Dennis MacAlistair Ritchie (1941-2011) was an American computer scientist who created the C language and co-developed the UNIX operating system with Ken Thompson. For his contributions, Ritchie received numerous awards including the Turing Award (1983), National Medal of Technology (1998), and IEEE Richard W. Hamming Medal (1990).

C Language Tutorial from Beginner to Advanced​

1. C Programming Fundamentals​

Basic C Program Structure​

C:
#include <stdio.h> // Preprocessor directive

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

Basic Data Types​

  • int: integer numbers
  • float: single-precision floating point
  • double: double-precision floating point
  • char: single character
  • void: empty type

Variables and Constants​

C:
int age = 25;
const float PI = 3.14159;
char initial = 'D';

2. Operators and Expressions​

Arithmetic Operators​

C:
int a = 10, b = 3;
int sum = a + b;  // 13
int remainder = a % b; // 1

Relational and Logical Operators​

C:
if (a > b && b != 0) {
printf("a is greater than b and b is not zero\n");
}

3. Control Structures​

Conditional Statements​

C:
if (score >= 70) {
printf("Passed\n");
} else if (score >= 50) {
printf("Remedial\n");
} else {
printf("Failed\n");
}

Loops​

C:
// For loop
for (int i = 0; i < 10; i++) {
printf("%d ", i);
}

// While loop
int j = 0;
while (j < 10) {
printf("%d ", j);
j++;
}

4. Functions​

C:
// Function declaration
int add(int a, int b);

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

// Function call
int result = add(5, 3);

5. Arrays and Strings​

C:
// Array
int numbers[5] = {1, 2, 3, 4, 5};

// String
char greeting[] = "Welcome";

6. Pointers​

C:
int var = 20;
int *ptr = &var; // ptr stores address of var

printf("Value of var: %d\n", *ptr); // Pointer dereferencing

7. Structures and Unions​

C:
struct Student {
char name[50];
int id;
float gpa;
};

union Data {
int i;
float f;
char str[20];
};

8. Dynamic Memory Management​

C:
int *arr = (int*)malloc(5 * sizeof(int)); // Allocation
if (arr == NULL) {
printf("Memory allocation failed\n");
exit(1);
}

// Use memory
for (int i = 0; i < 5; i++) {
arr[i] = i * 2;
}

free(arr); // Free memory

9. File Handling​

C:
FILE *file = fopen("data.txt", "w");
if (file == NULL) {
printf("Failed to open file\n");
return 1;
}

fprintf(file, "Sample text for file\n");
fclose(file);

10. Advanced Concepts​

Macros and Preprocessor​

C:
#define SQUARE(x) ((x) * (x))
#define DEBUG 1

#if DEBUG
printf("Debug mode active\n");
#endif

Bit Manipulation​

C:
unsigned int flags = 0;
flags |= 0x1; // Set bit 0
flags &= ~0x1; // Clear bit 0
int bit = (flags >> 3) & 0x1; // Get bit 3

Recursive Functions​

C:
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}

11. Modular Programming​

Header File​

C:
// mymath.h
#ifndef MYMATH_H
#define MYMATH_H

int add(int a, int b);
int subtract(int a, int b);

#endif

Implementation​

C:
// mymath.c
#include "mymath.h"

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

int subtract(int a, int b) {
return a - b;
}

12. Debugging and Optimization​

Debugging Techniques​

  1. Use strategic printf statements
  2. Utilize debuggers like gdb
  3. Check compiler warnings
  4. Use static analyzers

Code Optimization​

  1. Avoid unnecessary loops
  2. Use efficient algorithms
  3. Minimize memory access
  4. Utilize register variables when appropriate

13. Best Practices​

  1. Write clear comments
  2. Use descriptive naming
  3. Break code into small functions
  4. Handle errors properly
  5. Write portable code
By mastering all these concepts, you'll become an advanced C programmer capable of developing system applications, embedded systems, or even contributing to operating system development and new programming languages.







Complete C Language Guide with Meanings and Uses​


1. Introduction to C​

What is C?​

C is a procedural programming language developed in 1972 by Dennis Ritchie at Bell Labs. It is widely used for system programming, embedded systems, and low-level development due to its efficiency and control over hardware.

Why Learn C?​

✔ Foundation for other languages (C++, Java, Python)
✔ High performance (close to hardware)
✔ Portable (works on many platforms)
✔ Used in OS development (Linux, Windows kernels)

2. Basic Structure of a C Program​

Example Code:​

C:
#include <stdio.h> // Header file for input/output functions

int main() {        // Main function (entry point)
printf("Hello, World!\n");  // Print to console
return 0;       // Exit program successfully
}

Explanation:​

PartMeaningUsage
#include <stdio.h>Includes standard I/O libraryNeeded for printf(), scanf()
int main()Program entry pointWhere execution begins
printf()Prints outputDisplays text on screen
return 0;Exits programIndicates success

3. Data Types in C​

Primitive Data Types:​

TypeMeaningUsage
intInteger (whole numbers)int age = 25;
floatFloating-point (decimal)float pi = 3.14;
doubleDouble-precision floatdouble bigNum = 3.14159;
charSingle characterchar letter = 'A';
voidNo typeUsed in functions that return nothing

Example:​

C:
int age = 30; // Integer
float salary = 4500.50; // Floating-point
char grade = 'A'; // Character

4. Variables & Constants​

Variables:​

  • Used to store data.
  • Must be declared before use.
C:
int count = 10; // Integer variable
float price = 99.99; // Float variable

Constants:​

  • Fixed values that cannot change.
C:
const float PI = 3.14159; // Constant (read-only)

5. Input & Output (I/O)​

Printing Output (printf)​

C:
printf("Value: %d", 100); // %d = integer
printf("Name: %s", "Alice"); // %s = string

Reading Input (scanf)​

C:
int age;
scanf("%d", &age); // Reads an integer


6. Operators​

Arithmetic Operators​

C:
int a = 10, b = 5;
int sum = a + b;   // Addition (+)
int diff = a - b;  // Subtraction (-)
int mul = a * b;   // Multiplication (*)
int div = a / b;   // Division (/)
int mod = a % b; // Modulus (%)

Comparison Operators​

C:
if (a == b) // Equal to
if (a != b)  // Not equal
if (a > b)   // Greater than
if (a < b) // Less than

Logical Operators​

C:
if (a > 0 && b > 0) // AND (both true)
if (a > 0 || b > 0)  // OR (either true)
if (!(a == b)) // NOT (inverse)

7. Control Structures​

If-Else​

C:
if (age >= 18) {
printf("Adult");
} else {
printf("Minor");
}

Loops​

For Loop​

C:
for (int i = 0; i < 5; i++) {
printf("%d\n", i);  // Prints 0 to 4
}

While Loop​

C:
int i = 0;
while (i < 5) {
printf("%d\n", i);
i++;
}

8. Functions​

Definition & Usage​

C:
// Function declaration
int add(int a, int b);

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

// Function call
int result = add(5, 3); // Returns 8

9. Arrays & Strings​

Arrays​

C:
int numbers[5] = {1, 2, 3, 4, 5}; // Integer array
printf("%d", numbers[0]); // Prints 1

Strings​

C:
char name[] = "John"; // String (array of chars)

printf("%s", name);    // Prints "John"

[HR][/HR]

10. Pointers

Basics of Pointers​

C:
int num = 10;
int *ptr = &num;  // Pointer stores address of 'num'

printf("%d", *ptr); // Dereferencing (prints 10)

11. Structures​

Defining a Structure​

C:
struct Person {
char name[50];
int age;
};

// Usage
struct Person p1 = {"Alice", 25};
printf("%s is %d years old", p1.name, p1.age);

12. File Handling​

Reading & Writing Files​

C:
FILE *file = fopen("data.txt", "w"); // Open for writing
fprintf(file, "Hello, File!");       // Write to file
fclose(file); // Close file


13. Dynamic Memory Allocation​

malloc() & free()​

C:
int *arr = (int*)malloc(5 * sizeof(int)); // Allocates memory
arr[0] = 10;
free(arr); // Releases memory

​

C is a powerful, efficient, and widely used language for system programming, embedded systems, and game development. Mastering C helps in understanding how computers work at a low level and serves as a foundation for learning C++, Python, and other languages.
 
Relate Threads
C
C bởi Administrator,
Latest Threads
C
C bởi Administrator,

Facebook Comment

Search Google Web Search Google Images Search Google Voice Search Google Videos Search Maps Translate Word
🔍
GE
Google Experiment
Visit Google Experiment
⋮
CS
Code Saya
Visit Code Saya
⋮
SK
Sekolah Koding
Visit Sekolah Koding
⋮
HF
Huggingface
Visit Huggingface
⋮
SL
Sololearn
Visit Sololearn
⋮
LM
Learnx
Visit Learnxinmyminutes
⋮
w3s
W3schools
Visit w3schools
⋮
CW
Codewars
Visit Codewars
⋮
GG
Geeksforgeeks
Visit Geeksforgeeks
⋮
EXC
Exercism
Visit Exercism
⋮
EDX
EDX
Visit EDX
⋮
Add Shortcut
WhatsApp

Customer Service

CS 1

Mr.Ibnu

Loading jadwal...

Hubungi via WhatsApp
CS 2

Mr.Husein

Loading jadwal...

Hubungi via WhatsApp
CS 3

Mr.Hasan

Loading jadwal...

Hubungi via WhatsApp
Top Bottom

Translate Website

Upload Custom Icon

coding Coding
programmer Programmer
webmaster Webmaster
banners.png Banners
Home
What's New Resources Media Gallery
Record your forum activity and save it as MP4
> INITIALIZING ISE CONNECTION...
> BYPASSING SECURITY PROTOCOLS...
> ESTABLISHING WORMHOLE LINK...
> Starting XenForo engine... [DONE]
> Calibrating singularity Hosting parameters... [DONE]
> Establishing Forum Style... [DONE]
> The Programmer Community ready in 3... 2... 1.