Appendices
The appendices collect reference sheets, suggestions for further reading, and a glossary of terms to help you understand and apply C programming concepts.
Appendix A: Reference sheets
A.1 Common C functions
Standard input/output (stdio.h):
printf: Prints formatted output to the standard output.scanf: Reads formatted input from the standard input.fprintf: Prints formatted output to a file.fscanf: Reads formatted input from a file.fopen: Opens a file.fclose: Closes a file.fgets: Reads a string from a file.fputs: Writes a string to a file.
String handling (string.h):
strlen: Returns the length of a string.strcpy: Copies a string.strncpy: Copies a specified number of characters from a string.strcat: Concatenates two strings.strncat: Concatenates a specified number of characters from a string.strcmp: Compares two strings.strncmp: Compares a specified number of characters from two strings.
Memory management (stdlib.h):
malloc: Allocates memory.calloc: Allocates memory and initializes it to zero.realloc: Reallocates memory.free: Frees allocated memory.
Mathematical functions (math.h):
sqrt: Computes the square root.pow: Raises a number to a power.sin,cos,tan: Trigonometric functions.fabs: Computes the absolute value of a floating-point number.
A.2 C syntax cheat sheet
Variable declarations:
int x;
float y;
char z;
Control structures:
// If-Else
if (condition) {
// code
} else if (condition) {
// code
} else {
// code
}
// For Loop
for (initialization; condition; increment) {
// code
}
// While Loop
while (condition) {
// code
}
// Do-While Loop
do {
// code
} while (condition);
Functions:
return_type function_name(parameters) {
// code
return value;
}
Pointers:
int *ptr;
ptr = &variable;
value = *ptr;
Appendix B: Further reading and resources
These resources go deeper into C programming and its advanced topics.
Books:
- “The C Programming Language” by Brian W. Kernighan and Dennis M. Ritchie
- “C Programming: A Modern Approach” by K.N. King
- “C Primer Plus” by Stephen Prata
Online courses:
- Harvard’s CS50: Introduction to Computer Science
- Coursera’s C for Everyone: Programming Fundamentals
Websites:
Appendix C: Glossary of terms
- Array: A collection of elements of the same type stored in contiguous memory locations.
- Buffer overflow: A condition in which data exceeds a buffer’s storage capacity and overwrites adjacent memory.
- Compiler: A program that translates source code into machine code.
- Dangling pointer: A pointer that points to a memory location that has been freed.
- Dynamic memory allocation: Allocating memory storage at runtime, using functions such as
malloc,calloc, andrealloc. - Function prototype: A declaration of a function that specifies the function’s name, return type, and parameters.
- Library: A collection of precompiled functions and definitions that programs can use for added functionality.
- Pointer: A variable that stores the memory address of another variable.
- Struct: A user-defined data type in C that groups related variables of different types.
- Variable: A named storage location in memory that holds a value.