C Programming
main()
All C programs should contain a main() function that follows the format
Functions
Functions are self-contained bundles of code that can be called for execution by main()
Variables
Used in programs to store pieces of information that may change and may be used to dynamically influence the program.
int
Stores a signed integer value such as 314 or -314
8 bytes for 64-bit machines
4 bytes for 32-bit machines
2 bytes for 16-bit machines
float
Stores a signed floating-point number such as 3.234
4 bytes
double
Stores a large floating-point number
8 bytes
char
Stores a single character
1 byte
printf
Prints out to the screen
%n
Print nothing
printf("test %n");
%d
Decimal value
printf("test %d, 123);
%s
String Value
printf("test %s", "123");
%x
Hex value
printf("test %x", 0x123);
%f
Float
printf("test %f", 1.308);
scanf
Generally used to get input from the user
strcpy/strncpy
One of the most dangerous functions used in C.
Purpose is to copy each character in the source string into the destination string.
Dangerous because there is no checking of the source's size before it is copied over to the destination.
If the source is is larger than space allocated for the destination, overflow conditions are likely.
strncpy is a safer alternative
Last updated