C BASICS Flashcards
What are C filez
C files are source code for your program
How are C files executed
They are compiled with a compiler (gcc for instance) to create an executable file
Variables always have a type
Example
int i;
char c;
How are arrays declared
type var_name[num_of_items]
eg.
// array of 32 contiguous int
int my_array[32];
What’s a structure?
A complex data type declaration that
defines a physically grouped list of
variables to be placed under one name
in a block of memory
Declaration and creation of structure
struct structure_name {
type name;
…
};
struct structure_name var_name;
What are Functions
Functions:
●
Sequence of program instructions that perform a specific task,
packaged as a unit
●
May take arguments as input information
●
Compute something
●
May return a result
●
Functions can call functions
Parameters and return values must have a type
Functions syntax
return_type function_name(type param1, type2 param2, … )
[ block ]
example
int my_func(int a, char b)
[ block ]
All C program starts from where?
The main function
Aka the entry point
From the main function, you can call other functions
What happens when main returns
The program stops
What’s are blocks in C
Blocks or code blocks are sections of code which are grouped together. Blocks
consist of one or more declarations and statements.
Blocks are delimited by curly braces { and }
What is a char in C
‘letter’ (single quotes)
The value of a character is its ASCII code (man ascii)
What are strings in C
“string” (double quotes)
Evaluates to the address in memory of the first character of the string
Arithmetic operators in C
+ addition, - subtraction, * multiplication, / division, % modulo (integer remainder)
What does ++var, var– do?
Increment and decrement
++var // Increment var by 1, value of the expression is the value of var after the increment
var– // Decrements var by 1, value of the expression is the value of var before the decrement