Lesson 17

Variable-length argument length
Is when we have functions that have unspecified number of arguments (eg.
int printf(const char *format, ...);
)We must use variable argument headers
stdarg.h
.We must use the following macros
va_start
,va_arg
,va_list
,va_end
.
Command line arguments
int main(int argc, char * argv[]){}
argc is the number of arguments, argv is a list of pointers to strings. (eg../program arg1 arg2
→argc == 3
,argv == {“./program”, “arg1”, “arg2“}
)
CLI redirecting
Redirect input into program uses the redirect input symbol
<
(eg.sum < input
)Normally program output is displayed in screen, redirection grabs said input and sends it somewhere else.
Redirecting output into another program uses the pipeline symbol
|
(eg.random | input
)Redirect output into program uses the redirect output symbol
>
(eg.hello > out
)Redirect output appending it to another program using the append output symbol
>>
(eg.hello >> out
)
File processing (need to practice)
rb | Read an existing file |
wb | Create binary file for writing. Discards current content if file exists |
ab | Appends content to end of file. Open or create file in binary format. |
rb+ | Open existing binary file for reading and writing |
wb+ | Create binary file for update. Discards current content if file exists |
ab+ | TODO |
Program termination (need to practice)
You will need the
stdlib.h
module.You can use the
atexit
function to register a function upon a successful termination programtakes an argument which is a pointer to a function with no arguments
Volatile
- the
volitile
type qualifier may indicate that the variable may be changed by another program or by the computer’s hardware
Suffixes for integer constants
Specifying the types of integer and floating-point constants:
u
orU
for an unsigned integerl
orL
for a long integerul
,lu
,UL
orLU
for an unsigned long integer
Suffixes for Floating-Point constants
Integer constant is not suffixed, its type is determined by the first type capable of storing a value of that size
Suffixes are
f
orF
for a floatl
orL
for a long double
Subscribe to my newsletter
Read articles from Arty directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
