fork download
  1. #include <iostream>
  2. using namespace std;
  3. void showArray(int numbers[], const int SIZE);
  4.  
  5. int main() {
  6. //____________________________________________________________
  7. //| Intel processors |
  8. //|1974- 8086 - Each instruction is 8 bits: 01001010 |
  9. //| 80186 |
  10. //|1985- 80286 |
  11. //| |
  12. //|1991- 80386- 16 bit processor (instructions are 16 bits) |
  13. //| 10101010101010101 |
  14. //| |
  15. //|1995- 80486 32 bit processor (32 bit instructions) |
  16. //| 100101010010101010101010 |
  17. //|2000- 64 bit processor - 64 bit instructions |
  18. //| 1001010101001010110001011010 |
  19. //|Memory addresses are 16 bits. |
  20. //|0000000000000000 00000000 |
  21. //|0000000000000001 00000000 |
  22. //|0000000000000010 00000000 |
  23. //|0000000000000011 00000000 |
  24. //|0000000000000100 00000000 |
  25. //| |
  26. //|0000000011001000 00000000 |
  27. //|1000 000000000 |
  28. //|1111111111111111 00000000 |
  29. //|__________________________________________________________|
  30. int num1;
  31. int num2;
  32. int sum;
  33. cin>>num1;
  34. cin>>num2;
  35. sum = num1 + num2;
  36. cout<<"Enter number 1: "<<num1<<endl;
  37. cout<<"Enter number 2: "<<num2<<endl;
  38. cout<<"The sum of the two numbers is: "<<num1<<" + "<<num2<<" = "<<sum<<endl;
  39. //Array concept:
  40. const int SIZE = 5;
  41. int numbers[SIZE] = {1,2,3,4,5};
  42. int values[SIZE] = {1,2,3,4,5};
  43.  
  44. showArray(numbers,SIZE);
  45. cout<<numbers<< endl;
  46. if(numbers == values)
  47. {
  48. cout<<"They have the same base address."<<endl;
  49. }
  50. else
  51. {
  52. cout<<"Not the same base address."<<endl;
  53. }
  54. /*
  55. Binary numbers (2 digits) 0 1
  56.  
  57. 0000 0
  58. 0001 1
  59. 0010 2
  60. 0011 3
  61. 0100 4
  62. 0101 5
  63. 0110 6
  64. 0111 7
  65. 1000 8
  66. 1001 9
  67. 1010 A
  68. 1011 B
  69. 1100 C
  70. 1101 D
  71. 1110 E
  72. 1111 F
  73.  
  74. Hexadecimal numbers: (16 digits) 0 1 2 3 4 5 6 7 8 9 A B C D E F
  75.  
  76. 0 0 F D F C 4 8
  77. 00000000
  78. */
  79. //Introduction to pointers:
  80. int value = 3;
  81. int* ptr = &value;
  82. cout<< value<<" pointer value transfer cell holder: "<< ptr<<endl;
  83. /*
  84. Example:
  85. 0000000000000000000000000000001
  86. int numbers [3]={1,2,3};
  87. string cities[3] = {"New York", "Boston", "Phoenix"};
  88. cout << cities [1];
  89.   cities[0] 00000001 000000000000000000000000001
  90. 00000000
  91. 00000000
  92. 00000000
  93. cities[1] 00000010 000000000000000000000000010
  94. 00000000
  95. 00000000
  96. 00000000
  97.   cities[2] 00000011 000000000000000000000000011
  98. 00000000
  99. 00000000
  100. 00000000
  101.  
  102. */
  103. string cities[3] = {"New York", "Boston", "Phoenix"};
  104. cout <<"String array number "<<1<<" contains : "<< cities [1]<<endl;
  105. //Example # 5:
  106. char grades[5] = {'A','B','C','D','E'};
  107. cout<<"Student 1 Grade: "<<grades[1]<<endl;
  108. /*
  109. [0] 01000001 = 65 = 'A' ASCII table
  110. D B
  111. 0 = 0
  112. 1 = 1
  113. 2 = 10
  114. 3 = 100
  115. 01000001= 64 + 1 = 65
  116. ASCII Table is the international to Standard to arange bits into numbers
  117. and converts them into letters
  118. Grade[0] 01000001 = 65 = 'A'
  119. Grade[1] 01000010 = 66 = 'B'
  120. Grade[2] 01000011 = 67 = 'C'
  121. Grade[3] 01000100 = 68 = 'D'
  122. Grade[4] 01000101 = 69 = 'E'
  123. */
  124.  
  125. return 0;
  126. }
  127. void showArray(int numbers[], const int SIZE)
  128. {
  129. for(int i=0; i<SIZE; i++)
  130. cout<<"This is a number "<<i<< " in the array: "<< numbers[i]<<endl;
  131. }
  132.  
  133.  
Success #stdin #stdout 0s 5324KB
stdin
3
4
stdout
Enter number 1: 3
Enter number 2: 4
The sum of the two numbers is: 3 + 4 = 7
This is a number 0 in the array: 1
This is a number 1 in the array: 2
This is a number 2 in the array: 3
This is a number 3 in the array: 4
This is a number 4 in the array: 5
0x7ffe94d64fc0
Not the same base address.
3 pointer value transfer cell holder: 0x7ffe94d64fbc
String array number 1 contains : Boston
Student 1 Grade: B