Data Tpes rules
int / int = int
double / int = double
print data type of a variable
Syntax: typeid(&variableName).name()
int main()
{
int x = 4 ;
cout << typeid(&x).name(); // print the type of &x
return 0;
}
/* Ouput:
⏩ [ int * ]
This means data type of (&x) is 'pointer type (int*)'
*/
sizeof()
- size of varaible in bytes
#include <iostream>
int main() // assume a 32-bit application
{
char* chPtr{}; // chars are 1 byte
int* iPtr{}; // ints are usually 4 bytes
long double* ldPtr{}; // long doubles are usually 8 or 12 bytes
std::cout << sizeof(chPtr) << '\n'; // prints 4
std::cout << sizeof(iPtr) << '\n'; // prints 4
std::cout << sizeof(ldPtr) << '\n'; // prints 4
return 0;
}