C++

¡Supera tus tareas y exámenes ahora con Quizwiz!

Floating-point Literals

A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. You can represent floating point literals either in decimal form or exponential form.

Method

A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.

Identifiers

A name used to identify a variable, function, class, module, or any other user-defined item. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9).

Scope

A region of the program where variables can be declared.

Block

A set of logically connected statements that are surrounded by opening and closing braces. Blocks begin with a { symbol, end with a } symbol, with the statements to be executed being placed in between. Example: { cout << "Hello World"; // prints Hello World return 0; }

Character Literals

A type of literal in programming for the representation of a single character's value within the source code of a computer program. In C++, A character literal is composed of a constant character. It is represented by the character surrounded by single quotation marks.

Boolean Literals

A value of true representing true. A value of false representing false. Note: You should not consider the value of true equal to 1 and value of false equal to 0.

Variable DECLARATION

A variable declaration provides assurance to the compiler that there is one variable existing with the given type and name so that compiler proceed for further compilation without needing complete detail about the variable. A variable declaration has its meaning at the time of compilation only, compiler needs actual variable definition at the time of linking of the program. A variable declaration is useful when you are using multiple files and you define your variable in one of the files which will be available at the time of linking of the program. You will use extern keyword to declare a variable at any place. Though you can declare a variable multiple times in your C++ program, but it can be defined only once in a file, a function or a block of code.

Variables

A variable provides us with named storage that our programs can manipulate. which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable. This means that when you create a variable you reserve some space in memory. The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C++ is case-sensitive.

Interger Literals

An integer literal can be a decimal, octal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, 0 for octal, and nothing for decimal. An integer literal can also have a suffix that is a combination of U and L, for unsigned and long, respectively. The suffix can be uppercase or lowercase and can be in any order.

What are the basics of C++?

C++ Basic Syntax Object, Class, Methods, Instance Variables

Comments

Comments are portions of the code ignored by the compiler which allow the user to make simple notes in the relevant areas of the source code. Example: Single line: Starts with // and continue until the end of the line. Can also start with /* and end with */ Multi-line: start with /* and end with */

Constants

Constants refer to fixed values that the program may not alter and they are called literals. Constants can be of any of the basic data types and can be divided into Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values. They are treated just like regular variables except that their values cannot be modified after their definition.

3 places variables can be declared

Local variables, formal parameters, global variables.

Two kinds of expressions

Lvalues and Rvalues

Objects

Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors - wagging, barking, eating. An object is an instance of a class.

String Literals

Represents a sequence of characters that together form a null-terminated string. The characters must be enclosed between double quotation marks.

Reserved keywords

Reserved words may not be used as constant or variable or any other identifier names.

Variable DEFINITION

Tells the compiler where and how much storage to create for the variable. A variable definition specifies a data type, and contains a list of one or more variables of that type Example: type variable_list;

Semicolon ;

The semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. Example: x = y; y = y + 1; add(x, y);

Modifier

Used to alter the meaning of the base type so that it more precisely fits the needs of various situations.

2 ways to define constants

Using #define preprocessor. Using const keyword. Example: #define identifier value const type variable = value; Note: It is a good programming practice to define constants in CAPITALS.

Local Variables

Variables that are declared inside a function or block are local variables. They can be used only by statements that are inside that function or block of code. Local variables are not known to functions outside their own.

Formal parameter

an object or reference declared as part of a function declaration or definition, or in the catch clause of an exception handler, that acquires a value on entry to the function or handler; an identifier from the comma-separated list bounded by the parentheses immediately following the macro name in a function-like macro definition; or a template-parameter. Parameters are also known as formal arguments or formal parameters.

What are the five basic elements of a C++ program?

input, output, arithmetic, conditional, and looping

rvalue

The term rvalue refers to a data value that is stored at some address in memory. An rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right- but not left-hand side of an assignment. Note: Numeric literals are rvalues and so may not be assigned and can not appear on the left-hand side.

Whitespace

The term used describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Example: int age; The space in between int and age is whitespace

Data type modifiers

signed, unsigned, long, short

Class

A class can be defined as a template/blueprint that describes the behaviors/states that object of its type support.

Instance variables

Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.

lvalue

Expressions that refer to a memory location is called "lvalue" expression. An lvalue may appear as either the left-hand or right-hand side of an assignment. Note: Variables are lvalues and so may appear on the left-hand side of an assignment.

Global Variables

Global variables are defined outside of all the functions, usually on top of the program. The global variables will hold their value throughout the life-time of your program. A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration.

Type Qualifiers

Provide additional information about the variables they precede.


Conjuntos de estudio relacionados

314: Exam 4 (Chapter 44, 45, 46, 47)

View Set

Analgesics Pharmacology Homework

View Set

Section 9 - chpts 46, 49, 50, 51

View Set

PMP错题集(强化练习200一)

View Set

¿Como estas hoy? How are you today?

View Set