-
Smart People
1. What is the difference between Const Char and Char, or Const Int or Int?
2. In what type of situations do I use Const and what type to use normal char,long,int?
3. How to save a String into a Memory? How to retrieve the address of the saved string?
4. How to delete it after saving it?
5. How to generate a randomized number without using "time();ctime();" functions?
6. How to determine the user's OS?
7. How to write a key to the Registry?
8. How to Retrieve a Value from a Key in the Registry?
9. How to delete a Key In the Registry?
10. How to change the color of the text(Console Programs)
11. Is it possible to change the font of the text(Console Programs)
Questions are for the people that are smart.
-
1: anything "const" cannot be modified after initialization.
2: use it anytime you want to remind yourself that something should not be changed. Used also in functions where you pass a value by reference, or using a pointer, and dont want to be able to modify the value inside of the function.
3:Strings are always in memory. use new char[len] to create a new string. Save the address in a char* variable.
4: see above (last sentance)
5: srand(rand()) should work fine.
6: API function. Check MSDN
7-9: See above.
10: Yes, Use the SetConsoleTextAttribute() function.
Z.
-
1. & 2. Also const allows the compiler to consider inlining since a variable can be replaced with a constant. Next to performance it also advocates encapsulation and protection; Passing const parameters disallows changing any of it's variables either directly or trough any non const functions. Const should always replace #define macros, because they are type safe.
3. Strings can be stored in local buffers as well, which is a better solution if you want to use memory more efficiently and perform better: char[buffersize] where buffersize is constant. Stings as other variables are accessible trough their name, if not then they are out of scope, which means you tried to access it where you earlier disallowed it to be.
4. when a buffer lifetime ends depends where you define it, usually it only exist until the {} block ends in which it is defined. C Strings on the heap are not automatically removed and have to be manually removed with delete[] Cstring.
7-9 check out the references on these in msdn:
RegOpenKeyEx
RegCloseKey
RegQueryValueEx
RegCreateKeyEx
RegSetValueEx
RegDeleteKey
-
6. Since a program has to be compiled for another OS on another compiler, it's not necessary to find out which system it is running on: either your program doesn't care if it's totally ANSI, or it won't compile (an app using WinAPI can NEVER work on a Mac)
-
6. Or do you mean find out the windows version?
GetVersionEx is what you want then.