C
ANSI C
Dennis Ritchie, Brian Kernighan
statically typed, procedural, platform dependent
not memory safe
no garbage collector
#include <stdio.h>
int main() {
return 0;
}
C89
GCC + binutils GDB
malloc
calloc
realloc
typedef aka aliasing is useful.
sizeof is more useful than you realize.
Avoid goto at all times. Before you use it, think twice. Then think again and again.
Dijkstra wanted systems to be mathematically provable, so said GOTO is harmful
Avoid global variable. It can be accessed and modified everywhere, which is dangerous.
Avoid void pointers. It can be ugly looking, as an example:
*((char*)examp) = 'z'; // When casting to char before dereferencing.
Avoid register variable. (Last I checked it was deprecated. Also, the compiler is better at optimization than you.)
Avoid reinterpret_cast.
The difference between C and Java is Java does not require a newline. This is because of how parsers in those days was implemented.
http://www.gidnetwork.com/b-59.html Don’t use scanf.
“Alternative” (ternary operator) to if-else: condition ? true-expression : false-expression
Example:
a = --b ? b : (b = -99);
Cprogramming.com Line Count Programming Challenge fix
Just be aware that the solution they give you doesn’t tell you how to use it.
It says that you should use “count filename.txt” but I think that most people just starting out would be unaware of the fact that you need to compile correctly in order to use “count” as a command in the first place.
Notice the int main, which are usually varied this way:
int main(int argc, char **argv)
int main(int argc, char *argv[])
This lets you compile with a name:
g++ -o name-of-your-program name-of-your-program.c
If you compile without the -o flag, then you just do this:
./a.out filename.txt
Use the -o flag for a name other than a.out. Don’t use “test” as a name by the way.
Memory Allocation
Stack vs Heap
Bitwise Operations
& bitwise AND
| bitwise OR
^ bitwise XOR
<< left shift
>> right shift
~ bitwise NOT
Fork, Exec
Structures
Socket Programming
“Socket programming is a method of creating network communication channels (sockets) between networked devices, allowing them to send and receive data. It is a common way for computers to communicate over a network and is used to implement client-server applications, where one device acts as the server and listens for incoming connections, and the other device(s) act as the client(s) and connect to the server to exchange data.”
Server code
Client code
C
]