Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
c [2020/06/18 02:22]
paul [Mutable]
c [2020/10/23 02:53] (current)
Line 1: Line 1:
 ====== C and C++ ====== ====== C and C++ ======
  
-====C++ Interview questions====+===== C declerations ===== 
 + 
 +A c decleration can be read by following this rule and knowing about precedence. 
 + 
 +Go left when you can and right when you must. 
 + 
 +<code> 
 +char *(*(**foo [][8])())[]; 
 +</code> 
 + 
 +foo is an array to an array of 8 pointers to poiners to a function that returns 
 +a pointer to an array of pointers to char 
 + 
 +===== C++ Interview questions =====
  
 I was given a pop quiz by a non-tech interviewer once on c++. Here was his questions: I was given a pop quiz by a non-tech interviewer once on c++. Here was his questions:
Line 91: Line 104:
 This way you can use a macro expansion in a if else statement with no curly braces This way you can use a macro expansion in a if else statement with no curly braces
 where more than one statement would mess stuff up. where more than one statement would mess stuff up.
 +
 +===== C Declerations =====
 +
 +First, understand the breakdown of a decleration in c.
  
 ===== Rule of Three ===== ===== Rule of Three =====
Line 135: Line 152:
 An ''%%std::pair%%'' is an object that holds a pair of objects. An ''%%std::pair%%'' is an object that holds a pair of objects.
  
-<code c++>+<code cpp>
 // pair::pair example // pair::pair example
 #include <utility>      // std::pair, std::make_pair #include <utility>      // std::pair, std::make_pair
Line 185: Line 202:
 function. function.
  
-<code c++>+<code cpp>
 std::map<int, std::string> myMap; std::map<int, std::string> myMap;
 myMap.insert(std::make_pair(1, "mango")); myMap.insert(std::make_pair(1, "mango"));
Line 191: Line 208:
  
 ===== Memory Leaks ===== ===== Memory Leaks =====
 +
  
 For every new there must be a delete. Use the following valgrind command to For every new there must be a delete. Use the following valgrind command to
Line 224: Line 242:
  
 Example: Example:
-<code c++>+<code cpp>
 int array[5] = { 1, 2, 3, 4, 5 }; int array[5] = { 1, 2, 3, 4, 5 };
 for (int& x : array) for (int& x : array)
     x *= 2;     x *= 2;
 </code> </code>
 +
 ===== Debugging ===== ===== Debugging =====
  
Line 312: Line 331:
 sf::Sprite *re_sprite_hair, *re_sprite_body, *re_sprite_eyes; sf::Sprite *re_sprite_hair, *re_sprite_body, *re_sprite_eyes;
 </code> </code>
 +
 +===== Smart Pointers =====
 +
 +The STL library provides three types of "smart pointers", %%std::unique_ptr%%, %%std::shared_ptr%% and %%std::weak_ptr%%.
 +
 +
  • c.1592446942.txt.gz
  • Last modified: 2020/06/18 02:22
  • by paul