Table of Contents

C

C is a versatile, mature and efficient language.

Expressions are a combination of operators and operands. An expression followed by a semmicolon (“;”) is a statement (it is an action)

C concepts Memory Management Structs Debug messages Random numbers

Defines

In C you can define stuff that's quickly replaced by the preprocessor.

Let's say you have the following program:

#include <stdio.h>
int main()
{
	printf("Hello, World!\n");
#ifdef DEBUG
	printf("Secret debug info!\n");
#endif
	return 0;
}

Compile it with gcc -o prog -c prog.c -DDEBUG. Your program will print out the secret debug info in addition to its regular output. This is useful for debugging and more.

Storage-class specifiers

Make a variable's storage class more explicit to the compiler.

Block-scope static variables will keep their values between function calls. They're only initialized once at program startup, unlike regular function variables.

File-scope static variables (outside of any function) are restricted to the current source file only. You can't access them from another source file.

Notes


However, string literals are stored read-only and **cannot be modified**: ``char* s;``
If you want to make a mutable string, declare it as an array of characters: ``char s[];``
For example: ``thinkpad->price = 800;`` (``thinkpad`` is a pointer to a ``struct laptop thinkpad`` struct)
This is useful instead of writing it as ``(*thinkpad).price = 800;``

See also


https://beej.us/guide/bgc/ → Great funny introduction to C https://c-faq.com/index.html → C FAQs, very useful https://www.learn-c.org/ → wip C guide

http://web.archive.org/web/20080217222203/http://c.snippets.org/ Useful public domain C snippets

https://www.andreinc.net/2023/02/01/demystifying-bitwise-ops#number-systems interesting article about binary operators and memory in general

https://verplant.org/oo_programming_in_c.shtml OOP?