Data Allocation Flashcards

1
Q

pointer

A

variable that holds a memory address, rather than holding data. Indicated by a *

don’t declare multiple pointers on one line

must be declared to another variable of same type, not just to a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

pointer’s reference operator

A

&, obtains variable’s address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

dereference operator

A

prepended to a pointer’s variable name to retrieve that data to which the pointer variable points

*valPointer = 10; // changes someInt to 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

NULL means

A

nothing

when checking if a pointer is NULL, only use the value; don’t use a deference pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Syntax errors

A

Occurs when there is an error in the code that prevents the program from compiling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Runtime Error

A

Program is running but encounters an issue with data, that compiler couldn’t predict during compilation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

calloc

A

allocates a block of memory for an array of elements, initializing all bits in the allocated memory to zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

malloc(bytes)

A

specifies the number of bytes to allocate in a memory. found in stdlib.h library. returns a void pointer of memory address to the memory location. returns null if function failed to allocate memory (all memory is used up)

(double*)malloc(sizeof(double));
The double above converts the call from a void to a double returner, but not necessary because it automatically does this in C.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how many bits in an int?

A

32 bits, 4 bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

free(pointerVariable)

A

deallocates a memory block pointed to by a given poitner=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Memory Leak

A

Occurs when a program allocates memory but loses the ability to access the allocated memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Garbage collection

A

Automatic process of finding and freeing unreachable allocated memory locations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Unusable Memory

A

Memory locations that have been dynamically allocated but can no longer be used by a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

strchr(sourceStr, searchChar)

A

Returns NULL if searchChar does not exist in sourceStr, Else, returns pointer to first occurrence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

strrchr(sourceStr, searchChar)

A

Returns NULL is searchChar does not exist in sourceStr. Else, returns poitner to LAST occurrence (searches in reverse)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

strstr(str1, str2)

A

Returns NULL if str2 does not exist in str1. Else, returns a char pointer pointing to the first character of the first occurrence of string str2 within string str1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Dynamically Allocated Array

A

determining the total number of bytes needed to store the desired number of elements, using the following form:

pointerVariableName = (dataType*)malloc(numElements * sizeof(dataType))

18
Q

Statically allocated array

A

declare arrays to have a fixed size

19
Q

fgets

A

name, size, how (stdin)

20
Q

strcat

A

concatenates the string at the end of a given array

21
Q

1 byte = x bits

A

8 bits (wide), which is the amount of data stored at a single address

22
Q

True or False: In this example, the scalar variables were arranged in memory in the order in which they were declared

23
Q

True or False: Scalar variables of the same data type were packed together.

24
Q

True or False: For each of the two array variables, the first element is adjacent to the second element in memory

25
Q

True or False: The result of incrementing an int pointer by 1 is the next sequential address in memory.

A

False.

Adding 1 to a pointer variable increments it by the size of the variable type, so that it points to the next consecutive value of that type. Since an int is 4 bytes, it takes 4 consecutive addresses to store an int, so incrementing an int pointer by 1 adds 4 to the address.

26
Q

Code

A

The region where the program instructions are stored

27
Q

Static Memory

A

The region where global variables (variables declared outside any function) as well as static local variables (variables declared inside functions starting with the keyword “static”) are allocated. Static variables are allocated once and stay in the same memory location for the duration of a program’s execution

28
Q

The Stack

A

The region where a function’s local variables are allocated during a function call. A function call adds local variables to the stack, and a return removes them, like adding and removing dishes from a pile. Because this memory is also automatically allocated and deallocated, it is also called automatic memory.

All non-static, local variables inside functions are located on the stack.

29
Q

pass by pointer / pass by reference

A

used to return two values, by putting a * before a parameter name and & before the corresponding argument variable

30
Q

(*structPtr).membername is equivalent to

A

structPtr->membername;

31
Q

True or False: Like Python, C has a garbage collector that automatically frees dynamically allocated memory when it is no longer referenced in the program.

A

False.

In C programs, dynamically allocated memory must be explicitly deallocated using the free library call.

32
Q

True or False: Static variables are called “static” because their values can’t be reassigned

A

False.

Static variables can be assigned new values and retain their values between function calls.

33
Q

Number of Bytes a char stores:

34
Q

number of bytes for an ip address

35
Q

number of bytes for string

36
Q

Pointer to a variable goes into the….

37
Q

number of bytes for char pointer

38
Q

purpose of sizeof()

A

counts number of bytes

39
Q

number of bytes in a double