+ 1
Can someone tell me how variable definitions work?
I need help on this assignment for school.
4 Respuestas
+ 3
#include <iostream>
using namespace std;
int main() {
//declares 5 variables. Their types are int, float, double, char, and bool. Their names are i, flt, dbl, ch, and b.
int i;
float flt;
double dbl;
char ch;
bool b;
//sets their values (initializes). You need to remember to use the right data type.
i = 5;
flt = 3.14;
dbl = 3.1415926;
ch = ‘$’;
b = false;
//you can also declare and initialize at the same time:
int hi = 6;
//now, using them:
cout << i << endl;
//outputs 5
//you can change their values after initializing:
i = 156;
cout << i << endl;
//outputs 156
}
+ 2
What do you need to know about them?
Just how to declare a variable or something specific?
+ 2
to declare variable tell compiler the name and type of variable but to define variable give every thing about variable and allocate space for it
+ 1
I guess how how to declare a variable.