I have a list containing many questions about C++...some of them were answered in these forums, but there are always more!
11(ANSWERED). In a division of int by int, is the result an integer or a real number? I know that if the result is written to an int variable there will be rounding, but what happens when the result is written to a float or when it's used as output with cin?
16. Is dynamic memory automatically returned to the system when the program ends, or I have to use delete?
17. How are data files (graphics, sound, binary, text, etc.) put into the EXE file and how are they used in the C+ code? I know external files can be used with the file r/w functions easily, but what about files that don't have a path? They are inside the EXE. How does it work?
19(ANSWERED). Is there a pi constant in cmath or cstdlib? And what is M_PI ? when defining pi or any number with too many digits, how many digits are significant? How many of them actually get into the floating-point variable? and do the other digits affect the translation of pi into binary?
20(ANSWERED). If I'm not mistaken, giving values with { } is only possible when initializing an array in the declaration line, like this: int a[]={2,6,4,2,4};
Does this also work with objects?
1 2 3 4 5 6 7 8 9
|
class A
{
public:
int a;
float b;
bool c;
};
A obj{6,4.2f,true};
|
21. Usually there are many functions in a project that are not used. For example, the iostream library is included for i/o operations, but I only need cin and cout and their << operator functions. Does the compiler still incude the whole library? Compiled libraries maybe yes, but what about a cpp file? I have the source of a library as a header file with all function declarations and a cpp file with their definitions. In the object file there are probably all the contents of the cpp file, but in the linking stage - does the compiler eliminate functions that aren't used?
23. In
float a=0;
, does the compiler automatically convert the 0 into 0.0f in the compilation process or using 0 means there will be type casting in run time so using 0.0f in the code is faster?
24. In pointer arithmetics, do members of objects considered "defined object of their type"? For example, if there's class A with members a,b and c, all of type int, and an object obj of type A, does &(obj.a)+1 give a pointer to to obj.b?
Indeed, I have lots of questions. XD