Advertisement
Kagalive

Different ways to init vars

Sep 30th, 2020 (edited)
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. //Different ways to declare variables
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.   /Ints
  11.   int i1 = 1;
  12.   cout << "i1 = " << i1 << endl;
  13.   int i2;
  14.   i2 = 2;
  15.   cout << "i2 = " << i2 << endl;
  16.   int i3(3);
  17.   cout << "i3 = " << i3 << endl;
  18.   int i4{ 4 };
  19.   cout << "i4 = " << i4 << endl;
  20.  
  21.   //doubles
  22.   double d1 = 3.3;
  23.   double d2 = 11;
  24.  
  25.  
  26.   //chars
  27.   char c1 = 'a';
  28.   cout << "ci = " << c1 << endl;
  29.  
  30.   bool flag = false;
  31.  
  32.   auto a1 = 1; //int
  33.   auto a2 = 3.3; //double
  34.   auto a3 = 'c';  //char
  35.   auto a4 = "hello";  //c*
  36.   auto a5 = true;  //bol
  37.   auto a6 = 3L; //Long
  38.   auto a7 = 1'000'000'000'000; //Long Long
  39.   auto a8 = 0xFF; //int (255) hex literal
  40.   auto a9 = 0b111; //int (7) binary literal
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement