Chapter 4 C++ Primer

Ace your homework & exams now with Quizwiz!

What gets converted here? while (cin >> s)

while condition converts cin to a bool

Unary operator

Act on one operand. address-of(&)

binary operator

Act on two operands. == or *

What does associativity do?

Determines how operators with the same precedence are grouped. Operators can be either right associative or left associative.=

What is the name for this operator? %

Modulo

Ternary Operator

Takes three operands.

What is the comma operator?

The comma operator takes two operands, which it evaluates from left to right. It also guarantees the order in which its operands are evaluated.

What is a member access operator?

The dot and arrow operators provide member access. ex- n = (*p).size(); n = p->size();

Is this valid in C++? if (val) { }

Yes, val is converted to a bool.

When would you use the postfix increment operator?

When you want to use the original as a value but also want to increment the value;

How could you convert this integer to a constant int? int i;

const int i

How do you get the number of elements in an array using the sizeof operator?

constexp size_t i = sizeof (somePointer)/sizeof(*samePointer);

Provide a use of the comma operator in a for loop.

for(vector<int>::size_type ix = 0; ix !- ivev.size(); ++ix, --cnt)

What is the difference in conversion here - if (cp) while (*cp)

if (cp) // true if the pointer cp is not zero while (*cp) // true if *cp is not the null character

How do you create a reference to an array itself?

int (&ir)[6] = ia; Must know size of array

How do you create a pointer to an array itself?

int(*ip)[6] = &ia; Must know size of array

What type (lvalue or rvalue) do dereference and subscript operators yield?

lvalue

lvalue vs rvalue

lvalue expression yields an object or a function.

What is the value of j? What is i++ called? int i = 0, j; j = ++i; in i = 0, j; i = i++;

postfix increment operator 1) j = 1; 2) j = 0;

When we use an object as an rvalue, what do we use from that object? What about lvalue?

rvalue - we use the object's value(it's contents) lvalue - we use the object's identity (its location in memory)

What is an implicit conversion?

something similar to this - int ival = 3.541 +3; //3.541 gets cut off

What is the sizeof Operator?

the sizeof operator returns the size, in bytes, of an expression or a type name. sizeof (type) sizeof expr


Related study sets

Agents to Control Blood Glucose Levels

View Set

Chapter 4 : OSI - Transport Layer

View Set

Parent-Child Nursing Set 2-2 (Chapters 25, 26, 27, 28, and 29)

View Set

Chapter 17: Preoperative Nursing Management

View Set

Module 12 Pediatric Gastrointestinal and Respiratory

View Set

NURS 6320 Group 9 ch 29, 30, 32, 36

View Set

Chapter 2 Nature of Insurance, Risk, Perils and Hazards

View Set