Wednesday, July 8, 2009

C++ code statements....?

I've been ask to choose 4 different types of fundamental data types in C++ then write C++ code statements to declare and initialise a variable of each type...I really dont understand what this question is talking about but 4 data types I could think of are:


Integers, Float, Characters and Double


Could someone clarify what the question means and please a little help on it?????????? Thanks guys and gals =).........

C++ code statements....?
declaring is like saying there is an identifier called with "...."


example:


int i; (we delared an integer i)





initializing the variable


i = 0; (initial value of i is 0)





declaring and initializing at the same time is like:


int i = 0;





the 4 data types are as follows:


int (for integers)


float (for numbers with decimal points)


char (for characters)


double (for higher precision numbers)
Reply:Sounds like you understand it! Just write 4 statements that declare and inititalize each of those types!
Reply:It's pretty basic stuff.... Decare a variable of each type, e.g.





int num;


float cost;


bool choice;


// etc etc





Then initialize them by assigning each a value...





num=1;


float=1.0


bool = true;





Alternatively, you could just declare and initialize together,





int num=1;


float cost=1.0;


bool choice=true;
Reply:Sorry sis, mi no save so mi nonap ansarim displa
Reply:struct myvariablen{


int ia;


float fa;


char ca;


double da;


};





then in programm u can use it like this:


myvariablen myvar;


myvar.fa = 3.2;


myvar.ca = "a";


myvar.ia="2";

hamper

No comments:

Post a Comment