Skip to content

cybersecurity-dev/awesome-c-programming-language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

About

Awesome C Programming Language

Topics

Resources

License

Stars

Watchers

Forks

Contributors