Skip to content

Latest commit

 

History

History
300 lines (230 loc) · 12.3 KB

File metadata and controls

300 lines (230 loc) · 12.3 KB

Awesome C Programming Language Awesome

ANSI C | C99 | C11 | C17 | C23

YouTube Reddit

GitHub   YouTube   My Awesome Lists

📖 Contents

Declarations & Definitions

  • Function Declarations: A function can be declared several times in a program, but all declarations for a given function must be compatible;
    • the return type is the same
    • the parameters have the same type.
    float square(float x);

Function declarations do not allocate storage.

  • Function Definitions:
    float square(float x) {
        return x*x;
    }

Type Conversions

Arrays

Scope & Name Lookup

🔼 Back to top

int ival;
double darray[5];
  • ival has type int; we say &ival is a "pointer to int."
  • darray has type double[5]; we say &darray is a "pointer to an array of five doubles."
  • darray[3] has type double; we say &darray[3] is a "pointer to double."

You can find more details at the link

🔼 Back to top

#include <stdlib.h>
void *malloc(size_t size);
int ptrIArray[10];

malloc() takes a single argument (the amount of memory to allocate in bytes).

#include <stdlib.h>
void *calloc(size_t nelem, size_t elsize);

Allocates memory for an array of num objects of size and initializes all bytes in the allocated storage to zero.

realloc() is used to resize previously allocated memory (from malloc(), calloc(), or a previous realloc() call). It allows you to:

  • increase array size
  • shrink array size
  • avoid losing existing data
  • avoid manually copying the old array
#include <stdlib.h>
void *realloc(void *ptr, size_t size);
  • If ptr is a null pointer, realloc() shall be equivalent to malloc() for the specified size.
#include <stdlib.h>
void free(void *ptr);

Releases the specified block of memory back to the system.

You can find more details at the link

🔼 Back to top

A struct in C is a user-defined data type grouped together under one name. Its members can be of different data types (unlike arrays).

struct Person {
    char name[50];
    int age;
    float height;
};

int main() {
    struct Person p1;

    // Assign values
    strcpy(p1.name, "Alex");
    p1.age = 25;
    p1.height = 1.75f;

    printf("Name:\t%s\n", p1.name);
    printf("Age:\t%d\n", p1.age);
    printf("Height:\t%.2f\n", p1.height);

    return 0;
}

🔼 Back to top

A union is like a struct, but all members share the same memory location. This means:

  • A union can store only one member at a time
  • Size of union = size of its largest member
  • Writing to one member affects all others (because they overlap in memory)
union Data {
    int ival;
    float fval;
    char cval;
};

int main() {
    union Data Dval;

    Dval.ival = 26;
    printf("Dval.ival = %d\n", Dval.ival);

    Dval.fval = 3.14;
    printf("Dval.fval = %.2f\n", Dval.fval);

    Dval.cval = 'A';
    printf("Dval.cval = %c\n", Dval.cval);

    return 0;
}

🔼 Back to top

An enumeration (enum) is a user-defined data type that lets you assign names to integer constants.

  • Basic Enum Example
    enum Day {
        MONDAY,
        TUESDAY,
        WEDNESDAY,
        THURSDAY,
        FRIDAY,
        SATURDAY,
        SUNDAY
    };
    
    int main() {
        enum Day today = SATURDAY;
        printf("Today is day number: %d\n", today);
        return 0;
    }

You can find more details at the link

String Manipulation

Byte string Wide string Description
strcpy wcscpy Copies one string to another
strncpy wcsncpy Writes exactly n bytes/characters, copying from source or adding nulls
strcat wcscat Appends one string to another
strncat wcsncat Appends no more than n bytes/characters from one string to another
strxfrm wcsxfrm Transforms a string according to the current locale

String Examination

You can find more details at the link

Miscellaneous

🔼 Back to top

Signal Number Name Meaning Catchable?
1 SIGHUP Hangup detected ✔ Yes
2 SIGINT Interrupt (Ctrl+C) ✔ Yes
3 SIGQUIT Quit (Ctrl+) ✔ Yes
4 SIGILL Illegal instruction ✔ Yes
5 SIGTRAP Trace/breakpoint trap ✔ Yes
6 SIGABRT Abort ✔ Yes
7 SIGBUS Bus error ✔ Yes
8 SIGFPE Floating‑point exception ✔ Yes
9 SIGKILL Kill immediately ❌ No
10 SIGUSR1 User-defined signal 1 ✔ Yes
11 SIGSEGV Segmentation fault ✔ Yes
12 SIGUSR2 User-defined signal 2 ✔ Yes
13 SIGPIPE Broken pipe ✔ Yes
14 SIGALRM Alarm clock ✔ Yes
15 SIGTERM Termination request ✔ Yes
16 SIGSTKFLT Stack fault (Linux specific) ✔ Yes
17 SIGCHLD Child stopped/terminated ✔ Yes
18 SIGCONT Continue executing ✔ Yes
19 SIGSTOP Stop the process ❌ No
20 SIGTSTP Stop (Ctrl+Z) ✔ Yes
21 SIGTTIN Background read from TTY ✔ Yes
22 SIGTTOU Background write to TTY ✔ Yes
23 SIGURG Urgent condition on socket ✔ Yes
24 SIGXCPU CPU time limit exceeded ✔ Yes
25 SIGXFSZ File size limit exceeded ✔ Yes
26 SIGVTALRM Virtual alarm clock ✔ Yes
27 SIGPROF Profiling timer expired ✔ Yes
28 SIGWINCH Window size change ✔ Yes
29 SIGIO I/O now possible ✔ Yes
30 SIGPWR Power failure ✔ Yes
31 SIGSYS Bad system call ✔ Yes

You can find more details at the link

🔼 Back to top

🔼 Back to top

Severals

  • cJSON - Ultralightweight JSON parser in ANSI C.
  • Doxygen - Doxygen is a widely-used documentation generator tool in software development.

🔼 Back to top

Compiler/Debugger

  • MSVC & GCC & Clang - installation step of MSVC/GCC/Clang compiler in Windows
  • GCC & Clang - installation step of GCC/Clang compiler in Linux
  • OnlineGDB - Online compiler and debugger for C/C++

My Other Awesome Lists

You can access the my other awesome lists here

Contributing

Contributions of any kind welcome, just follow the guidelines!

Contributors

Thanks goes to these contributors!

License

CC0

🔼 Back to top