L1: C Warmup Flashcards
Parts of the C Standard Library, Categorized (15)
General:
- stdio.h - input/output
- stdlib.h - General Functions
- math.h - Math Functions
System:
- stddef.h
- stdarg.h
- signal.h
- setjmp.h
- limits.h
- locale.h
- time.h
Variables:
- float.h
- string.h
Testing/Debug:
- assert.h
- errno.h
- ctype.h
C Standard Library:
Input/Output Library
stdio.h
C Standard Library:
General Function Library
stdlib.h
C Standard Libary:
Testing and Debug Function Libraries
assert. h
errno. h
ctype. h
C Standard Libary:
System Libraries
stddef. h
stdarg. h
signal. h
setjmp. h
limits. h
locale. h
time. h
C Standard Library:
Variable Libraries
float. h
string. h
Fundamental Principles of Strings
- Strings are arrays of char’s where the last char is ‘\0’
- Declaration: char s[], s is an array variable that points to the array
- Assignment:
- s = “abc”
- Assigment with an empty string:
- s = “”
- s actually points to the null terminator “\0”
- Assign 0:
- s = 0
- s is a null pointer, points nowhere
Array Declarations
- Format:
- type name[size]
- example: char A[4]
- Once declared, A is a constant that can’t be modified
- The name ‘A’ is a pointer to the first element in the array
Array Declarations:
Undefined Declaration
Declared as a pointer:
char *B
or
char B[]
This allocates no storage, B is undefined
Primitive Types:
Integers
- types
- declaration
- values
- constants
- int
- declaration: int i;
- 16 or 32 bit (or 64)
- Constants:
- 0, 1, 10, 0xF, 010
- long,
- end in ‘L’
- 32, 64, or 128 bit (2x as long as int)
- Constants:
- 0L, 1L, 10L, 0xFL, 010L
Useful Functions:
Characters
(5 functions)
Library: ctype.h
Functions for testing a character against ranges:
isalpha(‘a’)
isdigit(‘0’)
iswhite(‘\t’)
isupper(‘A’)
islower(‘a’)
Useful Names and Functions:
Strings
include ‘<‘string.h’>’
- Concatenate:
- strcat(s, “more”)
- Copy String:
- strcpy(s, “more”)
- Compare:
- strcmp(s, t)
- returns 0 if equal, -1 if s<t>t</t>
- Length of String
- strlen(s)
- Find character in string:
- strchr(s,c)
- Returns pointer to first char in s that equals character c (or returns NULL)
Fundamentals of Arrays
(How Array Pointers Work)
- int A[4]
- Allocates room on stack, makes A point to first element
- *A = 21
- Stores the value 21 where A points to the first element
- *(A+1) = 6
- Stores the value 6 at the next int beyond where A points
- Arrays are pointers to the first element
- *(A+n) is equivalent to A[n]
Primitive Operations:
Bitwise Operations
- Bitwise AND:
- i & j
- Bitwise OR:
- i | j
- Bitwise NOT:
- ~i
- Bitwise XOR:
- i ^ j
- Bitwise Left Shift, Right Shift:
- a << b shift bits of a by b bits
- a >> b
C Primitive Types
- Integers
- int, long
- 32, 64 bit respectively(outdated)
- int, long
- Characters:
- char
- 8-bit
- char
- Arrays
- Pointers
- address of integer: int *p
- address of character: char *q
- Functions
- Names of subroutines
- form:
- returntype name(arg1, arg2,…){ //code}