C++ and Unix/Linux Basics Quiz
21 Questions
4 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the new keyword in C++?

  • To declare a pointer
  • To set a pointer to NULL
  • To delete a variable
  • To create a dynamic variable or object and return a pointer to it (correct)

A dangling pointer refers to a pointer that points to a memory location that has been deleted.

True (A)

What is recursion?

The process where a function calls itself to solve a problem.

One byte is equivalent to ______ bits.

<p>8</p> Signup and view all the answers

Match the following data types with their respective sizes in bytes:

<p>Int = 4 bytes Char = 1 byte Double = 8 bytes Float = 4 bytes</p> Signup and view all the answers

Which command is used to change file permissions in Unix/Linux?

<p>chmod (B)</p> Signup and view all the answers

The command 'mkdir' is used to delete files in Unix/Linux.

<p>False (B), True (A)</p> Signup and view all the answers

What does 'cin.clear()' do in C++?

<p>It clears the error state of the input stream.</p> Signup and view all the answers

The command 'ls -l' provides detailed information about files, including their ______.

<p>permissions</p> Signup and view all the answers

Which of the following is a persistent I/O manipulator for cin/cout?

<p>fixed (D)</p> Signup and view all the answers

Match the following commands with their functions:

<p>ls = List directory contents cd = Change directory cp = Copy files or directories rm = Remove files or directories</p> Signup and view all the answers

In C++, the type specifier '%d' is used for floating-point numbers.

<p>False (B), True (A)</p> Signup and view all the answers

What does 'argv' stand for in the context of command-line arguments?

<p>Argument vector</p> Signup and view all the answers

What is always stored in the first element of argv?

<p>The name of the program being executed (D)</p> Signup and view all the answers

String streams can only be used to write to files.

<p>False (B), True (A)</p> Signup and view all the answers

What is the output of a binary search on a sorted array if the target is not found?

<p>The output will typically be an index indicating 'not found' or a boolean false.</p> Signup and view all the answers

The __________ sorting algorithm repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.

<p>Bubble Sort</p> Signup and view all the answers

Match the following number systems with their characteristics:

<p>Decimal = Base 10 Binary = Base 2 Hexadecimal = Base 16 Octal = Base 8</p> Signup and view all the answers

Which operator is a unary operator among the following?

<p>~ (C)</p> Signup and view all the answers

In C++, when an array is passed to a function, a copy of the entire array is made.

<p>False (B), True (A)</p> Signup and view all the answers

What must be included to use string streams in C++?

<p>#include <sstream></p> Signup and view all the answers

Flashcards

Creating a variable that stores the memory address of another variable.

Pointer Declaration

Accessing the value stored at the memory address pointed to by a pointer.

Pointer Dereference

Creating memory during runtime using the 'new' keyword to allocate space in memory for variables.

Dynamic Memory Allocation (new)

A condition where memory used by a program is not properly deallocated or freed, thus causing loss of system resources.

Memory Leak

Signup and view all the flashcards

A programming technique where a function calls itself to solve a smaller instance of the same problem.

Recursion

Signup and view all the flashcards

Different operational states in VIM (e.g., command mode, insert mode, visual mode).

VIM Modes

Signup and view all the flashcards

Setting access rights for users (owner, group, others) for files and directories in Unix/Linux using octal numbers to manage read, write, and execute permissions.

chmod Permissions

Signup and view all the flashcards

Clears the error flags associated with the input stream cin (e.g., if an invalid input type is entered).

cin.clear()

Signup and view all the flashcards

Skips over a specified number of characters in the input stream cin. Useful for discarding unwanted input.

cin.ignore()

Signup and view all the flashcards

Creating an array-like data structure capable of dynamically resizing; similar to Java's ArrayList, stores elements of the same data type.

Vector Declaration

Signup and view all the flashcards

Opens a file for reading or writing; initializes a file stream object to access a physical file from a program.

File Stream .open()

Signup and view all the flashcards

Command-line arguments; argv is an array of strings, argc is the count of arguments (use with argc to avoid going beyond the array's bounds!).

argv/argc

Signup and view all the flashcards

Verifying if file stream operations were successful (e.g., .fail(), .is_open()).

File Stream Error Check

Signup and view all the flashcards

A method of passing arguments to a function where a copy of the argument is created and passed to the function. Changes made to the copy inside the function do not affect the original variable.

Pass-by-Value

Signup and view all the flashcards

A method of passing arguments to a function where the function receives a reference (or alias) to the original variable, not a copy. Changes to the argument inside the function directly affect the original variable.

Pass-by-Reference

Signup and view all the flashcards

Arrays are automatically passed by reference in C++. When an array is passed as an argument to a function, the function receives a pointer to the first element of the array, and changes made to its elements within the function affect the original array.

Pass Arrays to Functions

Signup and view all the flashcards

argc (argument count) is an integer that holds the number of command-line arguments given, and argv (argument vector) is an array of strings that contains the actual arguments.

argc & argv

Signup and view all the flashcards

Streams that work with strings instead of files or the console; used to read/write data into and from strings.

String Streams

Signup and view all the flashcards

A search algorithm that operates on sorted data by repeatedly dividing the search interval in half. Very efficient.

Binary Search

Signup and view all the flashcards

A search algorithm that checks each element of a data structure sequentially until a match is found.

Linear Search

Signup and view all the flashcards

Operations performed on binary numbers (e.g., AND, OR, XOR, NOT).

Binary Operations

Signup and view all the flashcards

Study Notes

CS 102 Final Study Guide

  • This is a study guide for the final exam. It is not exhaustive and should be used in conjunction with other learning materials.

  • Midterm 1 Content (Including chmod):

    • VIM:
      • What is VIM?
      • Different modes
      • Opening files from the command line
      • Entering/exiting insert mode
      • Saving and exiting VIM
    • Unix/Linux:
      • Overview of Unix/Linux commands (e.g., ls, cd, mkdir, rm, cp, ssh, scp, chmod)
      • Explanation of each command
      • Permission string meanings (for commands like ls -l)
      • Using chmod to change permissions for files and directories
      • Understanding octal number systems with chmod.
    • Input/Output:
      • Number system used with chmod (octal)
      • C++ input/output syntax (cin/cout)
        • Including necessary headers
        • cin.clear() and its function
        • cin.ignore() and its function
        • Wrapping cin in statements
      • Printf
        • Type specifiers (%f, %d, etc.)
        • Precision control
        • Left/right justification
      • I/O manipulators
        • Including headers
        • Persistent/non-persistent manipulators (setw(), setfill(), left, right, setprecision, fixed, showpoint, scientific, hex, dec).
    • Vectors:
      • Definition of vectors
      • Comparison to Java vectors
      • Vector declaration syntax
      • Accessing and assigning vector elements
      • Vector functions(.push_back(), size(), clear(), resize().)

Midterm 2 Content

  • Searching algorithms:
    • Linear search
    • Binary search
  • Sorting Algorithms:
    • Bubble sort
    • Selection sort
  • Insertion Sort:
    • Number systems (decimal, binary, hex)
    • Conversion between number systems
  • Binary Operations:
    • Binary operations (e.g., &, |, ^, <<, >>, ~)
    • Understanding unary operators
    • Understanding the differences between << and >>
  • Binary Application:
    • Using bitwise operations (set, clear, test bit)
    • Understanding the ASCII table (understanding that each character has a numeric value)

Pass-by-Value. Pass-by-Reference

  • Pass-by-value and pass-by-reference differences in function syntax, parameter passing and reference variables
  • Function calls and copy creation
  • Array and other data type automatic passing in C++

Pointers

  • Pointer declaration and setting
  • Pointer dereferencing
  • Dynamic variable creation
  • Memory management (deletion and NULL pointers)
  • Errors: seg fault, dangling pointer, memory leaks

File Streams

  • File streams Overview
  • Writing and reading to/from files using ifstream and ofstream
  • Opening, closing, checking for errors
  • Insertion/extraction operators
  • Error checking

String Streams

  • Similarities/differences to console/file streams
  • Using istringstream and ostringstream
  • Writing to and extracting from strings
  • Insertion/extraction operators.

Recursion

  • Definition of recursion
  • Function definition recognition of recursion
  • Parts of a recursive subroutine

Data Types

  • Data type sizes in bytes.
  • Number of bits in a byte
  • Data type values ranges

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

CS 102 Final Study Guide PDF

Description

Test your knowledge on C++ programming concepts and Unix/Linux commands with this comprehensive quiz. From pointers to file permissions, challenge yourself on various fundamental topics. Perfect for beginners looking to solidify their understanding of these essential programming tools.

More Like This

Use Quizgecko on...
Browser
Browser