Arrays, Strings, Randomness and Pointers Flashcards
(40 cards)
What is an example of signed int overflow in C?
When unsigned short int x = 65535; is assigned to short int y, y becomes -1.
What is the output of printf for variable c when c = x; with x = 65535?
Undefined behaviour.
What are the two types of arrays in C?
- 1D arrays
- 2D arrays
What does C not do with respect to arrays?
C does not perform bounds checking.
How are strings represented in C?
Strings are arrays of characters ending with a null terminator (0).
What does the function strlen(s) do in C?
Returns the length of the string (excluding the null terminator).
What is the purpose of srand(seed) in C?
Sets a new seed to change the sequence of random numbers.
What does the function rand() generate?
A pseudo-random integer between 0 and RAND_MAX.
What is the shape of the Normal (Gaussian) Distribution?
Follows a bell-curve shape.
What does the GNU Scientific Library (GSL) provide?
Better random number generators than rand().
What is the purpose of the function gsl_rng_set in GSL?
Sets the seed for the random number generator.
Fill in the blank: Strings in C are just arrays of characters ending with a ______.
null terminator.
True or False: C automatically checks for buffer overflows in arrays.
False.
What is the output of printf when using sprintf(buffer, “%s %d”, str, num)?
Formats and stores output into buffer.
What is a one-dimensional array in C?
An array that holds a fixed number of elements of the same type, initialized with specific values.
How can the size of an array be defined in C?
The size can be implicit and defined by its initialization.
What is an uninitialized array in C?
An array declared without an initial value, containing random data.
How is a two-dimensional array initialized in C?
An array of arrays initialized with specific values.
How do you access and set individual values in an array?
Using index notation, e.g., anArray[0] = 42; or array[3] = ‘Z’;
What is a string in C?
A string is an array of characters terminated by a null character (0).
What is the significance of the null terminator in strings?
It signals the end of the string to prevent the program from getting stuck.
True or False: Strings in C are enclosed in single quotes.
False.
What are functions in C?
Uniquely named groups of program statements that may accept parameters and return values.
What is the syntax for defining a function in C?
<return> functionName(<parameter>) { /* statements */ return <value>; }
</value></parameter></return>