Week 1 Review An Introduction To C
Week 1 Review An Introduction To C
● You can work together and collaborate on CAs, PAs, and LAs. We will have 5
quizzes throughout the semester and you must work on these alone.
● If you have trouble understanding a topic: you have Tutoring option through Upswing
channel, and the option to email me for help. Use the resources at your disposal.
Wednesday
● When a function is declared as int (like int main()), it means the function is expected
to return an integer value. The return statement inside the function specifies the exact
integer value that will be sent back to the place from which the function was called.
Thus, if a function is of type int, it must have a return statement that provides an integer
value. Return 0; indicates the function finished without running into any problems.
● Every statement ends with a ; to let the compiler know where one instruction finishes
and the next one starts. Think of it like a full stop at the end of a sentence in English.
● Whitespace refers to spaces, tabs, and newline characters. It helps make the code
readable, like spaces between words in a book. While the compiler usually ignores it,
proper whitespace is crucial for humans to understand and organize code better. So, it's
like the layout in a book - not needed for the story but essential for reading comfort.
● using namespace std; in C++ lets you use standard library tools with less typing,
like cout instead of std::cout, making code cleaner for beginners. However, it can risk
name clashes if another library uses the same names and, over time, can obscure
where certain functions come from. It's a useful shortcut for newcomers, but as you
delve deeper, being specific can prevent potential hiccups.
● iostream is a header file in the standard C++ library that includes tools for input-output
operations, like reading input or displaying output using streams (e.g., cin and cout). In
C++, a "library" is a collection of pre-compiled code, functions, or classes that you can
include in your program. It offers reusable functionalities without needing to write them
from scratch. Think of it as a toolbox, providing ready-made tools for specific tasks.
● cout
● cin
● Comments are annotations within the code that are not executed by the compiler.
They serve to provide explanations or notes to developers. There are two types: single-
line comments, initiated with // , which comment out everything to the right on the
same line, and multi-line comments, bounded by /* and */ , which can span several
lines. Comments enhance code readability and facilitate understanding, especially
during collaborative projects or revisiting one's own code at a later date.
● To output both a variable and a static string using cout, you employ the insertion
operator (<<). For instance, if you possess an integer variable named age and wish to
display it alongside the phrase "Your age is:", you'd write:
○ cout << "Your age is: " << age;
○ This approach concatenates and presents the static string and the variable's
value seamlessly.
● A variable serves as a symbolic name for a storage location in memory, where data,
such as a number or a string, can be stored, retrieved, and manipulated. Think of it as a
labeled box where you can keep an item; the label (ie. variable name) helps you identify
which box to access when you need the stored item (ie. the data). Each variable has a
specific data type, like int for integers or double for floating-point numbers, that dictates
the kind of data it can hold and the amount of memory allocated for it.
Friday
● History of Computer
● Lab activities