you have to initialize it into the "Constructor" which is a function without dataType and it's name is the same with the class name
EX:-
class Exforsys
{
private:
int a,b;
public:
Exforsys();
...
};
Exforsys :: Exforsys()
{
a=0;
b=0;
}
the EX from : http://www.exforsys.com/tutorials/c-plus-plus/class-constructors-and-destructors-in-c.html
I recommend this link for You Under the title "Constructors and destructors" :
http://www.cplusplus.com/doc/tutorial/classes/
You can also See : http://www.win.tue.nl/~maubach/university/education/online-references/cpp/swartz/notescpp/oop-condestructors/constructors.html
The constructor.
constructor
For global/static variables: yes.For auto variables: no.
Class Variables or Instances variables are variables that are declared inside a class and are available for the whole class. They are available for all instances of that class and are not specific to any method. Ex: public class Test { private String name = "Rocky"; } Here name is a class variable.
Reference variables
Static Variables are created when the class is loaded and continue to exist as long as the class is loaded/present in the JVM
The variables which are declared outside the main() function is known as global variables and they can be used anywhere in the program. And, the variables which used declare inside the main() function is known as local variables and they can be used inside the main() function only. Example: #include<stdio.h> #include<conio.h> int x,y; // global variables void main() { int a,b; // Local variables ------------ ---------------------- --------------------- getch(); }
When a function gets called, the processor first stores the address of the calling function in a structure called activisation structure and jumps to the called function. Then it allocates the memory for the local variables and initializes them. Then it does the processing in that function. After that it deallocates the memory allocated for the local variables and returns to the calling function. When a function gets called, the processor first stores the address of the calling function in a structure called activisation structure and jumps to the called function. Then it allocates the memory for the local variables and initializes them. Then it does the processing in that function. After that it deallocates the memory allocated for the local variables and returns to the calling function.
For global/static variables: yes.For auto variables: no.
By design. What else should it do? Of course you can initialize your variables explicitly: double pi = 3.0;
False. Variables declared within a particular member function are local to that function, and are automatically allocated and deallocated at entry and exit of the function.
Static functions are tied to a class, not to a particular object. A static function can only access static variables because it has no knowledge of member variables.
A linear function is any function that graphs to a straight line. What this means mathematically is that the function has either one or two variables with no exponents or powers. If the function has more variables, the variables must be constants or known variables for the function to remain a linear function.
Private variables can only be accessed from outside of a class by using any public function of that same class. Or this can be accomplished by using Friend functions.
Independent variables are the input value of a function (usually x) and dependent variables are the output value of the function (usually y).
These are normal variables declared within a class that are attached to an object instance of a class.
The constructor. It's run each time a new object is created, usually setup to initialize member variables, but it can do most anything.
Class Variables or Instances variables are variables that are declared inside a class and are available for the whole class. They are available for all instances of that class and are not specific to any method. Ex: public class Test { private String name = "Rocky"; } Here name is a class variable.
Class - A class can be defined as a template/ blue print that describe the behaviors/states that object of its type support.Classes in Java:A class is a blue print from which individual objects are created.A sample of a class is given below: public class Dog{ String breed; int age; String color; void barking(){ } void hungry(){ } void sleeping(){ } }A class can contain any of the following variable types.Local variables . variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.Instance variables . Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.Class variables . Class variables are variables declared with in a class, outside any method, with the static keyword.A class can have any number of methods to access the value of various kind of methods. In the above example, barking(), hungry() and sleeping() are variables.