Can someone tell me how variable definitions work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone tell me how variable definitions work?

I need help on this assignment for school.

26th Jan 2018, 6:54 PM
Jimin's excuse me
Jimin's excuse me - avatar
4 Answers
+ 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 }
27th Jan 2018, 2:25 AM
Jacob Pembleton
Jacob Pembleton - avatar
+ 2
What do you need to know about them? Just how to declare a variable or something specific?
27th Jan 2018, 1:39 AM
Jacob Pembleton
Jacob Pembleton - avatar
+ 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
27th Jan 2018, 4:19 AM
Ahmed Gad
Ahmed Gad - avatar
+ 1
I guess how how to declare a variable.
27th Jan 2018, 1:53 AM
Jimin's excuse me
Jimin's excuse me - avatar