why don't i need to call a constructor?

I’m coming from processing. So if i make a object i’m used for it being null. Take this for example:

  
    ofVec2f average;  
      
    printf("%f\n", average.x);  
    printf("%f\n", average.y);  

Why is average not null?

If i have this for example:

  
    testImage = new ofImage();  
    testImage->loadImage("knob_image_07.png");  

The code above won’t run if i remove the first line.

Can someone explain a litle?

in java everything is a pointer so when you declare a variable that variable is just a pointer to an object that you need to create using new.

in c++ you can declare variables as objects or pointers to objects explicitly with the * syntax. if you declare a variable without the * then it’s an object and you don’t need to create it later using new because it’s already constructed in the declaration. If you use the * then you have a pointer and you have to create the object that that variable will point to using new.

there’s also some differences that this introduces with java, for example in java if you do this:

  
  
PVector a = new PVector(3,2);  
PVector b = a;  
b.x = 5;  
  

now a.x is also 5 because b and a are internally pointers to the same object while in c++ this:

  
  
ofVec3f a(3,2);  
ofVec3f b = a;  
b.x = 5;  
  

won’t modify a cause b is a full copy of the object not a pointer to the original while:

  
  
ofVec3f * a = new ofVec3f(3,2);  
ofVec3f * b = a;  
b->x=5;  
  

will behave the same as in java modifying the original object pointer by both a and b.

google for heap vs stack allocation for more info.

Thanks for pointing out heap vs stack allocation, i never heard of it.
I just readed some but i’m kind of tired atm so i will continue tomorrow to see if i understand better.
I was never really sure when to use pointers and when not. Mostly i waited for the compiler to complain, but it’s coming to me now.