Comp 2710 Midterm study guide

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/128

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

129 Terms

1
New cards

Front

Back

2
New cards

"What is the datatype of z after executing: double x = 1

y = 2; auto z = x + y;"

3
New cards

"Which of the following are preprocessing directives?"

"#include is a preprocessing directive. 'using namespace some_namespace' is NOT a preprocessing directive."

4
New cards

"What is the final value of c in this code: int a = 1

b = 2; int c = a + b++; int d = a + ++b;"

5
New cards

"In C++ must functions be defined within classes?"

"False - Functions can be defined outside of classes as standalone functions."

6
New cards

"Which is an example of a function declaration/prototype/header?"

"int my_function(int

7
New cards

"What is the final value of y in: int x = 2

y; y = x++ + x + x;"

8
New cards

"What library must you include to use cin and cout?"

" - This library provides input/output stream functionality."

9
New cards

"What are makefiles used for?"

"Makefiles can include commands to compile a program from source code files

10
New cards

"What is a JOB in Jenkins?"

"A task or set of instructions that you want to automate in the Jenkins continuous integration system."

11
New cards

"What is GitHub?"

"A place for you to upload and maintain programming code

12
New cards

"What is the 'target' in a makefile?"

"A rule that contains some instructions

13
New cards

"What are the three different types of version control systems?"

"Local

14
New cards

"In a makefile with CC = g++ and OBJS = eval.o main.o

what is 'myprogram' in: $(CC) -o myprogram $(OBJS)?"

15
New cards

"Can you use conditionals in makefiles?"

"True - Makefiles support conditional statements for build logic."

16
New cards

"What is one benefit of separate compilation?"

"The ability to compile a program modularly and not have to recompile the entire program any time a change is made."

17
New cards

"In a makefile for compiling dtime.cpp and timedemo.cpp

what should fill blanks d) and e) in: timedemo.o : d)_ timedemo.h g++ -c e)_?"

18
New cards

"What happens when you commit something in git?"

"All content marked to be synchronized is committed as a snapshot to the primary git repo."

19
New cards

"Which is NOT a benefit of version control systems?"

"Immediate access to data - This is not typically listed as a primary benefit of version control."

20
New cards

"In a makefile

what should fill blanks a) and b) in: timedemo : a)_ b)_ g++ -c dtime.o timedemo.o -o timedemo?"

21
New cards

"What is the default filename the make utility looks for when you type 'make' without parameters?"

"Makefile - This is the default filename that make searches for."

22
New cards

"In C++ are you only allowed to have one constructor (no constructor overloading)?"

"False - C++ supports constructor overloading

23
New cards

"For file I/O with ifstream

what goes in blank 1) in: int a

24
New cards

"Where does a clause end in C++ (public

private

25
New cards

"What must you end your class or struct definition with?"

"A semi-colon - Class and struct definitions must end with a semicolon."

26
New cards

"For file I/O reading values a

b

27
New cards

"Can structs have constructors and destructors in C++?"

"True (the statement 'structs cannot have constructors and destructors' is False) - In C++

28
New cards

"If writing an implementation file for class 'Myclass' defined in 'myclass.h'

what should be included?"

29
New cards

"What is a stream in C++?"

"A stream represents some kind of input/output

30
New cards

"What is the default access modifier of a class in C++?"

"Private - Class members are private by default in C++."

31
New cards

"What is a destructor used for in C++?"

"To release memory allocated in the heap for one or more variables in the struct/class

32
New cards

"What part of memory is a pointer pointing to when using 'new'?"

"Heap - Dynamic memory allocation with 'new' allocates memory on the heap."

33
New cards

"What will line 15 print: double stuff[100]; double *p; p = stuff; for (i=0;i<100;i++) stuff[i] = i; cout << *(p + 5) << endl;?"

"5 - Pointer arithmetic: p points to stuff[0]

34
New cards

"Is a reference type exactly like a pointer except for the way you use it in the code?"

"False - References and pointers have fundamental differences beyond syntax (references cannot be null

35
New cards

"What happens with: int y = 22; int &x; x = y; cout << x << endl;?"

"You get a compile error because you have to initialize a reference variable when you declare it."

36
New cards

"If line 12 prints address 0x168 for &stuff

what will line 13 print for p (where p = stuff)?"

37
New cards

"What is printed on line 4: int y = 22; int &x = y; x = 25; cout << y << endl;?"

"25 - Since x is a reference to y

38
New cards

"Is a pointer a data type?"

"True - Pointer is a data type that stores memory addresses."

39
New cards

"What does it mean to dereference a pointer?"

"To go to the address the pointer is storing and work with data at that address

40
New cards

"Given structtype1 s1 and structtype1 * sptr = &s1

which statement initializes member1 of s1 to 22?"

41
New cards

"Given structtype1 s1 and structtype1 * sptr = &s1

which statement initializes member2 of s1 to 22 using the pointer?"

42
New cards

"What is preprocessing in C++?"

"The preprocessing phase handles directives like #include and #define before actual compilation begins."

43
New cards

"What is the purpose of the #include directive?"

"To include the contents of another file (typically header files) into the current file during preprocessing."

44
New cards

"What does 'using namespace' do?"

"It allows you to use names from a namespace without prefixing them with the namespace name."

45
New cards

"What is the difference between b++ and ++b?"

"b++ (post-increment) returns the current value then increments; ++b (pre-increment) increments first then returns the new value."

46
New cards

"What is auto keyword in C++?"

"auto allows the compiler to automatically deduce the type of a variable from its initializer."

47
New cards

"What is the purpose of function prototypes?"

"Function prototypes declare the function signature before its implementation

48
New cards

"What library provides file stream functionality?"

" - Provides ifstream

49
New cards

"What is separate compilation?"

"A technique where different parts of a program are compiled independently into object files

50
New cards

"What is an object file?"

"A compiled but not yet linked file (typically .o extension) containing machine code that needs to be linked with other object files."

51
New cards

"What is the purpose of the -c flag in g++?"

"The -c flag tells g++ to compile to object code without linking."

52
New cards

"What is the purpose of the -o flag in g++?"

"The -o flag specifies the name of the output file (executable or object file)."

53
New cards

"What does CC typically represent in a makefile?"

"CC is a variable that typically stores the compiler command (e.g.

54
New cards

"What does OBJS typically represent in a makefile?"

"OBJS is a variable that typically stores a list of object files needed for linking."

55
New cards

"What is the purpose of git add?"

"git add stages changes to be included in the next commit."

56
New cards

"What is the purpose of git push?"

"git push uploads local repository content to a remote repository."

57
New cards

"What is the purpose of git pull?"

"git pull fetches and merges changes from a remote repository to the local repository."

58
New cards

"What is a local version control system?"

"A VCS that maintains versions in a local database on a single computer."

59
New cards

"What is a central version control system?"

"A VCS with a single central server that stores all versions

60
New cards

"What is a distributed version control system?"

"A VCS where every user has a complete copy of the repository history on their local machine."

61
New cards

"What is ifstream used for?"

"ifstream (input file stream) is used for reading from files."

62
New cards

"What is ofstream used for?"

"ofstream (output file stream) is used for writing to files."

63
New cards

"What is the open() method used for in file streams?"

"The open() method opens a file and associates it with a stream object."

64
New cards

"What is the close() method used for in file streams?"

"The close() method closes the file associated with a stream

65
New cards

"What is the >> operator used for with streams?"

"The >> (extraction operator) reads formatted input from a stream."

66
New cards

"What is the << operator used for with streams?"

"The << (insertion operator) writes formatted output to a stream."

67
New cards

"What are the three access modifiers in C++?"

"public

68
New cards

"What does public access modifier mean?"

"public members are accessible from anywhere the object is accessible."

69
New cards

"What does private access modifier mean?"

"private members are only accessible within the class itself."

70
New cards

"What does protected access modifier mean?"

"protected members are accessible within the class and by derived classes."

71
New cards

"What is the default access modifier for struct members?"

"public - Struct members are public by default."

72
New cards

"What is constructor overloading?"

"Having multiple constructors with different parameter lists in the same class."

73
New cards

"What is a default constructor?"

"A constructor that takes no arguments

74
New cards

"What is a parameterized constructor?"

"A constructor that takes one or more parameters to initialize object data."

75
New cards

"When is a destructor called?"

"A destructor is called when an object goes out of scope or is explicitly deleted."

76
New cards

"What is the syntax for declaring a destructor?"

"~ClassName() - The destructor has the same name as the class with a tilde (~) prefix."

77
New cards

"What does 'new' operator do in C++?"

"'new' allocates memory dynamically on the heap and returns a pointer to the allocated memory."

78
New cards

"What does 'delete' operator do in C++?"

"'delete' deallocates memory previously allocated with 'new'

79
New cards

"What is a memory leak?"

"Memory that is allocated but never freed

80
New cards

"What is the difference between stack and heap memory?"

"Stack memory is automatically managed with fixed size; heap memory is manually managed and can grow dynamically."

81
New cards

"What is pointer arithmetic?"

"Operations on pointers (like p+1

82
New cards

"What does NULL or nullptr represent?"

"A special pointer value indicating that the pointer doesn't point to any valid memory location."

83
New cards

"What is the address-of operator in C++?"

"The & operator

84
New cards

"What is the dereference operator in C++?"

"The * operator

85
New cards

"What is the arrow operator in C++?"

"The -> operator

86
New cards

"What is the difference between array[i] and *(array+i)?"

"They are equivalent - both access the element at index i in the array."

87
New cards

"What happens if you dereference an uninitialized pointer?"

"Undefined behavior - likely a segmentation fault or garbage values."

88
New cards

"What happens if you delete the same pointer twice?"

"Undefined behavior - this is called double-free and can cause program crashes."

89
New cards

"Can you change what a reference refers to after initialization?"

"No - once a reference is initialized

90
New cards

"Can you change what a pointer points to after initialization?"

"Yes - pointers can be reassigned to point to different memory locations."

91
New cards

"Can a reference be null?"

"No - references must always refer to a valid object."

92
New cards

"Can a pointer be null?"

"Yes - pointers can have the value NULL or nullptr."

93
New cards

"What is pass-by-value?"

"Passing a copy of the argument to the function; changes don't affect the original."

94
New cards

"What is pass-by-reference?"

"Passing a reference to the argument; changes affect the original variable."

95
New cards

"What is pass-by-pointer?"

"Passing a pointer to the argument; allows indirect modification of the original."

96
New cards

"What is the purpose of const with pointers?"

"const can make the pointer constant

97
New cards

"What does 'const int* ptr' mean?"

"Pointer to constant int - the int value cannot be changed through ptr

98
New cards

"What does 'int* const ptr' mean?"

"Constant pointer to int - ptr always points to the same location

99
New cards

"What does 'const int* const ptr' mean?"

"Constant pointer to constant int - neither the pointer nor the pointed-to value can be changed."

100
New cards

"What is encapsulation?"

"Bundling data and methods that operate on that data within a single unit (class)

Explore top flashcards

Milgram
Updated 942d ago
flashcards Flashcards (62)
Resting Restless
Updated 164d ago
flashcards Flashcards (32)
Social influence
Updated 945d ago
flashcards Flashcards (22)
Renaissance
Updated 231d ago
flashcards Flashcards (25)
STM 005
Updated 822d ago
flashcards Flashcards (36)
Milgram
Updated 942d ago
flashcards Flashcards (62)
Resting Restless
Updated 164d ago
flashcards Flashcards (32)
Social influence
Updated 945d ago
flashcards Flashcards (22)
Renaissance
Updated 231d ago
flashcards Flashcards (25)
STM 005
Updated 822d ago
flashcards Flashcards (36)