Содержание
- 2. Practice Problem 1: Input a number and output it’s bits in a sequence.
- 3. Practice Problem 2: Find the sum of squares of numbers from 1 to N Input: 4
- 4. Practice Problem 3: Find the hypotenuse of a triangle (legs are given) Input: 3 4 Output:
- 5. Practice Problem 4: Find max and min of two numbers without using conditions Input: 3 4
- 6. Practice Problem 5: Find the number of paired bits in the binary representation of an integer
- 7. Practice Problem 6: Let’s consider sets of: Digits [10] Latin letters (both capital and lowercase ones)
- 8. Arrays Variable is like a cell in a storage room But what if we want to
- 9. Arrays a = You can think of the index as the distance from the leftmost element.
- 10. Arrays When creating an array, you need to specify its size: int a[6]; By default, as
- 11. Practice Task 1: A sequence of n numbers is entered on the keyboard. Print numbers in
- 12. Arrays and const qualifiers If we combine array modifier and const qualifier, we’ll create a const-qualified
- 13. Declaration point of an array int x[x]; Compilation error, x is undefined. int x = 2;
- 14. Arrays I would like to be able to use arrays even if the size is large.
- 15. What happens at the physical level When a program is launched, the operating system allocates a
- 16. What happens at the physical level Another example:
- 17. What happens at the physical level Example with an array (note, that array is placed on
- 18. What happens at the physical level The area of memory discussed is called the stack. What
- 19. Pointers We smoothly arrived at the concept of a pointer. What it is? Pointer is a
- 20. Operations with pointers 1) Unary operator &, aka address-of (don’t confuse with the binary bitwise operator
- 21. Operations with pointers 3) Incrementing / decrementing pointers. By adding a number to the pointer, you
- 22. Operations with pointers 4) Difference of two pointers. By subtracting two pointers, you will know the
- 23. Operations with pointers 5) Operator [], aka subscript operator. Applies to arrays. a[i] returns the array
- 24. Operations with pointers In fact, when the [] operator is applied to the array a, the
- 25. Operations with pointers It is possible to access memory not associated with the current array.
- 26. Dynamic memory You cannot allocate very large arrays, because the stack size is limited. But how,
- 27. Operators new and delete Operator new: Allocates new one cell.s Operator delete: Deallocates one cell. Operator
- 28. Operators new and delete, syntax One cell: Array: 4 in this case is the size of
- 29. Operators new and delete Now is the time to talk about how to declare arrays that
- 30. Example Input two arrays of doubles and output sum of these arrays.
- 31. Const qualifier and pointers Let me remind you that C ++ has a const keyword, which
- 32. Const qualifier and pointers A pointer to a const returns a const when dereferenced. A pointer
- 33. Swap Let's imagine the following problem: we want to swap the values of variables. Moreover, we
- 34. Swap When we pass an argument to a function by value (as in the previous example),
- 35. Swap We can improve the code a bit by keeping the const rule, which states: everything
- 36. References In fact, before the invention of C ++, the method I showed was the only
- 37. References In Python, for example, if we create a list and create a variable to which
- 38. References To create a reference to a variable in C ++, you must use the ampersand
- 39. References References can be passed to functions. In this case, we will NOT create a copy,
- 40. References Moreover, references can not only be received by functions, but also returned from them! However,
- 41. Const qualifier and references Just like with pointers, we can create references to constants. In this
- 42. Casts There is a so-called C-style cast operator, which allows you to convert variables of different
- 43. Casts static_cast: This is a compile-time conversion. If static_cast fails to convert the original variable to
- 44. Casts const_cast is a conversion "through" a constant. This is the only cast that violates the
- 45. Problem A sequence of 2D points is specified as a sequence of pairs (x, y). It
- 47. Скачать презентацию