Table of Contents

  1. Introduction
  2. Structures
  3. Classes
  4. Unions
  5. Enumerations

2.1 Introduction

2.2 Structures

void vector_init(Vector& v, int s) {
    v.elem = new double[s]; 
    v.sz = s;
}
struct Vector {
    double* elem;
    int sz;
};

void f(Vector v, Vector& rv, Vector* pv) {
    v.sz = 10;    
    rv.sz = 20;  
    pv->sz = 30;  
}

int main() {}
  1. How will the compiler likely arrange the memory layout, and why?
  2. How can reordering the members improve memory efficiency?
  3. Would making this a class instead of a struct change memory layout?