0

question about the way of coding in example of the program for C++ sizeof ....

why we must to declare var ?? the code :..... cout << "char: " << sizeof(char) << endl; cout << "int: " << sizeof(int) << endl; cout << "float: " << sizeof(float) << endl; cout << "double: " << sizeof(double) << endl; int var = 50; cout << "var: " << sizeof(var) << endl; /* Outputs char: 1 int: 4 float: 4 double: 8 var: 4 */

2nd Nov 2017, 8:07 PM
Amir Mehrabi
2 Respuestas
0
var is a variable that will allow you to store a data type in it. var can be 10, 20, 5. You need to declare the type of data type the variable is because you can add int variables together, but not a string and int. Each has its own functions etc. That requires he variable to be a certain type. Same for declaring an array. You can use the functions for arrays only once you have declared it as an array.
2nd Nov 2017, 8:41 PM
Rain
Rain - avatar
0
Thank you so much
3rd Nov 2017, 2:07 AM
Amir Mehrabi