Flashcards: C++ Functions Recursion and OOP — 85 cards

All cards

1Question

What is a data structure in computing?

Answer

A logical or mathematical model for collecting and organizing data.

2Question

What defines an algorithm in computer science?

Answer

A set of instructions or rules for solving a problem or task.

3Question

What programming paradigms does C++ combine?

Answer

Object-oriented programming with procedural C.

4Question

Why is C++ considered a multiparadigm language?

Answer

Because it combines object-oriented and procedural programming.

5Question

For what type of software is C++ especially suitable?

Answer

System software such as operating systems.

6Question

What two tools does a C++ development environment require?

Answer

A text editor and a compiler.

7Question

What is the first step in a basic Linux C++ workflow?

Answer

Creating a source file.

8Question

How do you compile a C++ source file named hello.cpp in Linux?

Answer

Using the command g++−ohellohello.cppg++ -o hello hello.cpp.

9Question

How do you run the compiled executable named hello in Linux?

Answer

By executing ./hello./hello.

10Question

What must a C++ program include to run properly?

Answer

Directives and at least one main function with executable statements.

11Question

What is cout used for in C++?

Answer

It is the standard output object for printing values or text.

12Question

What operator is used with cout to print values?

Answer

The stream insertion operator <<.

13Question

What is cin used for in C++?

Answer

It is the standard input object for reading data from the keyboard.

14Question

What operator is used with cin to read input?

Answer

The stream extraction operator >>.

15Question

Which data types are considered primitive in C++?

Answer

int, float, double, boolean, and char

16Question

What is a string in C++?

Answer

An object or sequence storing text as characters

17Question

Why does the extraction operator >> read only one word from input?

Answer

Because whitespace terminates the input

18Question

What must be called before getline() to read a complete line after formatted input?

Answer

cin.ignore()

19Question

What characters can C++ identifiers contain?

Answer

Letters, digits, and underscores

20Question

With which characters must C++ identifiers begin?

Answer

A letter or underscore

21Question

Are C++ identifiers case-sensitive?

Answer

Yes, they are case-sensitive

22Question

What characters and words are forbidden in C++ identifiers?

Answer

Whitespace, special characters, and reserved words

23Question

What does a namespace provide for identifiers like types and functions?

Answer

A distinct scope.

24Question

How do you access entities inside a namespace from outside?

Answer

Using the scope resolution operator ::.

25Question

What is a symbolic constant?

Answer

A named constant whose initialized value cannot be changed.

26Question

What is a function in programming?

Answer

A complete subprogram designed to perform a well-defined task.

27Question

What are the two types of C++ functions?

Answer

Library functions and user-defined functions.

28Question

What does a function prototype declare?

Answer

The return type, name, and parameter list followed by a semicolon.

29Question

What is the purpose of a function prototype?

Answer

To allow the function to be implemented later.

30Question

Which header provides functions like isdigit and tolower in C++?

Answer

The <cctype> header.

31Question

What defines a C-string in C programming?

Answer

A character array terminated by a null character.

32Question

What does the strcat function do with character arrays?

Answer

It appends one character array to another.

33Question

What is the purpose of the strcmp function?

Answer

It compares two strings.

34Question

What value does strlen return for a C-string?

Answer

The length of the C-string.

35Question

What does the push_back function do in a string object?

Answer

Inserts a character at the end of the string object.

36Question

What happens during a function call in execution?

Answer

Execution transfers to the called function until return or end.

37Question

With what kinds of arguments can a function be called multiple times?

Answer

Literal arguments, variables, or as part of larger expressions.

38Question

What allows C++ functions to be overloaded with the same name?

Answer

Differences in number or types of parameters.

39Question

Can return type alone distinguish overloaded functions in C++?

Answer

No, return type alone cannot distinguish overloads.

40Question

What does a function template define in C++?

Answer

A generic function with types determined at instantiation.

41Question

How is a function template instantiated?

Answer

By calling its name with template arguments in angle brackets followed by function arguments.

42Question

What is the signature of the generic sum template function?

Answer

T sum(T a,T b)T\ sum(T\ a,T\ b)

43Question

How can the sum template be instantiated for integers and doubles?

Answer

As sum<int>(x,y) or sum<double>(n,m).

44Question

What is recursion in programming?

Answer

A function calling itself to solve smaller problems of the same nature.

45Question

How does the Principle of Mathematical Induction prove statements?

Answer

By proving a base case, assuming the statement for k, and proving it for k+1.

46Question

What are the three steps of mathematical induction?

Answer

Prove the base case, assume P(k), then prove P(k+1).

47Question

What is the factorial recursion formula?

Answer

fact(n)=n×fact(n−1)fact(n)=n\times fact(n-1)

48Question

What is the base case for factorial recursion?

Answer

fact(0)=1fact(0)=1

49Question

What is the Fibonacci recursion formula?

Answer

f(n)=f(n−1)+f(n−2)f(n)=f(n-1)+f(n-2)

50Question

What are the base cases for Fibonacci recursion?

Answer

f(0)=0f(0)=0 and f(1)=1f(1)=1

51Question

What is the recursive power algorithm formula?

Answer

xn=x×xn−1x^n=x\times x^{n-1}

52Question

What is the base case for the recursive power algorithm?

Answer

x0=1x^0=1

53Question

When does a recursive sorted-array check return true?

Answer

For zero or one element.

54Question

What is the recursive formula for summing an array?

Answer

sumOfArray(a,n)=a[0]+sumOfArray(a+1,n−1)sumOfArray(a,n)=a[0]+sumOfArray(a+1,n-1) with sumOfArray(a,0)=0sumOfArray(a,0)=0.

55Question

What defines a palindrome sequence?

Answer

It reads the same left to right and right to left.

56Question

How does the recursive digit string to integer conversion algorithm work?

Answer

It converts the shorter prefix, multiplies by 10, then adds the final digit.

57Question

Who developed C++ and where?

Answer

Bjarne Stroustrup at Bell Labs.

58Question

In which year did Bjarne Stroustrup develop C++?

Answer

1979.

59Question

What features does an integrated development environment combine?

Answer

Code editing, compilation, and debugging support.

60Question

Name four examples of integrated development environments.

Answer

Code::Blocks, Eclipse, Sublime Text, and Visual Studio.

61Question

What languages does GCC provide compiler front-ends for?

Answer

C, C++, Objective-C, Fortran, Ada, and Go.

62Question

What additional support does GCC include besides compiler front-ends?

Answer

Runtime support libraries.

63Question

How does every C++ statement end?

Answer

With a semicolon.

64Question

What does the C++ compiler ignore in the code?

Answer

Whitespace.

65Question

What does the setw() manipulator do?

Answer

Sets the field width for the next insertion operation.

66Question

Which header declares the setw() manipulator?

Answer

The <iomanip> header.

67Question

What base does the dec manipulator format integers in?

Answer

Decimal base.

68Question

What base does the oct manipulator format integers in?

Answer

Octal base.

69Question

What base does the hex manipulator format integers in?

Answer

Hexadecimal base.

70Question

What does a void function return?

Answer

No value.

71Question

How can the parameter list of a void function be written?

Answer

As empty parentheses or as void.

72Question

What value does sqrt(16) return?

Answer

4.

73Question

What value does pow(5,3) return?

Answer

125.

74Question

What do size(), length(), and strlen(str.c_str()) return for "Rwanda Coding Academy"?

Answer

They each return 21.

75Question

Which overload does operate(5,2) select and what does it return?

Answer

The integer overload, returning 10.

76Question

Which overload does operate(5.0,2.0) select and what does it return?

Answer

The double overload, returning 2.5.

77Question

What allows a template's arguments to resolve to different types?

Answer

Using multiple type parameters like T and U.

78Question

What does an auto return type enable in template functions?

Answer

Compiler deduction of a common return type to avoid narrowing.

79Question

What is the formula for the sum of integers from 1 to n?

Answer

∑i=1ni=n(n+1)2\sum_{i=1}^{n}i=\frac{n(n+1)}{2}

80Question

What is the recursive formula for the sum of digits of n?

Answer

sum(n)=sum(⌊n/10⌋)+(n mod 10)sum(n)=sum(\lfloor n/10\rfloor)+(n\bmod 10)

81Question

What is the base case for the recursive sum of digits?

Answer

sum(0)=0sum(0)=0

82Question

What does a recursive palindrome check do when first and last elements differ?

Answer

It returns false.

83Question

How does a recursive palindrome check proceed when first and last elements match?

Answer

It recursively checks the inner sequence.

84Question

When does a recursive character printer stop?

Answer

At the '\0' character.

85Question

What does a recursive character printer do before recursing?

Answer

It prints the first character.

Test yourself with the quiz

Test your knowledge with 57 questions on C++ Functions Recursion and OOP.

1. Which description best defines a data structure?

2. A programmer writes ordered instructions that calculate a solution to a problem; what has the programmer created?

Take the quiz →

Read the study sheet

Review the complete course in the study sheet for C++ Functions Recursion and OOP.

See study sheet →

Similar courses

Create your own flashcards

Import your course and AI generates flashcards in 30 seconds.

Flashcard generator