DEV Community

hwangs12
hwangs12

Posted on

Core C++ OOP Concepts

Four concepts:

  1. Encapsulation - setting access level for whatever is inside a class
  2. Abstraction - creating a design of things you like

Things learned today

  • When you write static array and assign to a variable with less than x in array[x] then the rest of the space is by default filled in as 0 (in c++ 14)
  • If you do not specify the length of the array, then the size is size of element multiplied by how many you put in when you initialize
  • array as argument in a function parameter will 'read' only one element (int* aka pointer to int)

Image description

Compiler Warning

Top comments (1)

Collapse
 
pauljlucas profile image
Paul J. Lucas

While the sizeof the array will only be of int*, all the 10 ints are still there pointed to by the pointer. In C++ (and C), the "pointer-ness" of the left-most array parameter is converted to a pointer.

void f( int a[] );    // same as: void f( int *a );
void g( int a[][4] ); // same as: void g( int (*a)[4] );
Enter fullscreen mode Exit fullscreen mode

Neither C++ nor C actually has "array parameters" since they always decay into pointers. It's a hold-over from the New B language. While most of this is C-specific, the stuff about "array parameters" is true for C++ also.