C
What is C?
Dennis Ritchie wrote C at Bell Labs. The language is a few commands: a variable, a function, a condition, a loop, and a memory address. C++ adds classes and other rules on top of it. C# is a different language. The name is similar, but it is not C. A C program is compiled into machine code before it runs.
What is C used for?
C is chosen when speed and a small size are needed. The kernel of an operating system, a driver, and a microcontroller are its place.
- Parts of the Linux kernel
- A microcontroller program
- Another language's compiler
- The lower layer of a network tool
What can you do with C?
With C you read a file, count bytes, and reserve a place in memory. The language does not check for you. Stepping past the end of an array can break the program quietly. Writing a windowed site is not its ordinary job.
Is C hard to learn?
The words are few, but the address is hard. A pointer is a number of a place in memory. A wrong number can touch another program's memory. Not returning a reserved place fills the program slowly.
Advantages and limits
Advantage: the result can be small and fast, and the language itself changes little. Limit: ready comfort for text, a list, and an error is small. You write those yourself. A security mistake is expensive here.
Basic ideas
A variable's type says its size. A function ties a job to a name. A pointer stores an address, not the value itself.
- int stores a whole number
- char stores one byte
- if checks a condition
- return sends a value out of a function
A short example
This program writes one line on the screen and ends with 0. 0 usually means there was no error.
#include <stdio.h>
int main(void) {
printf("Hello\n");
return 0;
}Common questions
- Are C and C++ the same? No. C++ is built on C, but it is a separate language.
- Is C obsolete? No. It is used in a kernel, a driver, and a small device.
- Is C safe? The language does not stop you. A wrong address can break the program.