C/C++ Programming Language Flashcards
To master all the concepts pertaining the use of C and C++ in software development.
Makefiles
Yeah
Relational Operator “>”
Greater Than
malloc( ) and calloc( ) functions, what are they and how are they different?
malloc( ) and calloc( ) are library functions that allocate memory dynamically. Accomplished using heap segmenting. Both functions return pointers to the beginning of the memory , or NULL if the allocation failed.
malloc( ) allocates a memory block of a given size (in bytes) and returns a pointer to the beginning of the block. The memory, however, is not initialized. If we try to access the content of the memory block then we’ll get garbage values.
calloc( ) allocates AND initializes memory blocks to zero. Additionally, calloc takes two arguments, the number of blocks to be allocated, and the size of each block.
In either case, any use of these functions must be followed with a call of free( ) in order to deallocate the memory, else you have a memory leak.
The form of the “if” conditional statement
if(condition){statements}
4 phases of code development
1.Code 2.Save 3.Compile 4.Execute
The “Stack” As it pertains to the C language
Stack is a memory region where “local variables”, “return addresses of function calls” and “arguments to functions” are hold while C program is executed. CPU’s current state is saved in stack memory
Relational Operator “<=”
Less than or Equal To
calloc
Yeah?
Relational Operator “!=”
Not Equal To
Relational Operator “>=”
Greater than or equal to
Relational Operator “
Less Than
string
A string is a sequence of characters, more specifically it is an array of characters.
char
Used to specify individual characters (also bytes sometimes as they are only a single byte)
The “Heap” as it pertains to the C language
Heap is a memory region which is used by dynamic memory allocation functions at run time. Linked list is an example which uses heap memory.
int
used to specify integer data types.
What does a Compiler do
A Compiler converts human readable code into machine code.
double
Used top specify double precision floating point numbers
Relational Operator “==”
Equal To
Semaphore
Semaphore is a signaling mechansm (“I am done, you can carry on” kind of signal). For example, if you are listening to songs (assume it as one task) on your mobile and at the same time your friend calls you, an interrupt is triggered upon which an ISR signals the call processing task to wakeup.
A semaphore is a generalized mutex. In lieu of single buffer, we can split the 4 KB buffer into four 1 KB buffers (identical resources). A semaphore can be associated with these four buffers. The consumer and producer can work on different buffers at the same time.
free () -memory
Yeah?
What will the following command do? g++ helloworld.cpp -o hw
This command will compile the code in “helloworld.cpp” using G++ and output it with the name hw.out.
Mutex
A mutex is a locking mechanism used to synchronize access to a resource. A mutex provides mutual exculsion, either producer or consumer can have the key (mutex) and proceed with their work. As long as the buffer is filled by producer, the conusmer needs to wait, and vice versa. At any point, only one thread can work with the entire buffer.
bool
Stores Boolean Data, usually specific to C and C++ in software Development. You will usually not see this in embedded programming.
“chaining”
pertains to the combination of strings and variables, similar to how Python allows combinations of outpus in a print statements. This method is contingent on the use of “cout” in the iostream library.
strdup (something to do with strings I think)
Yeah
Syntax for Modulo “%” operator
remainder = numerator % denominator;
What is the “#” Operator in C/C++
Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. This process is called preprocessing. Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol.