Programmer/Tester- Aditya Gupta (aka Techy3.5 :-)
I used g++ to compile these on linux
1. Type casting of floating point numeral to integer (either automatic or by type casting)-
Conversion of floating point to integer is by taking the GIF (Greatest Integer Funtion) and NOT ROUNDING OFF
Greatest Integer Function(Maths,12th) it gives the integer part when the original number is written as integer+fractional part (where fractional part is less than 1 but positive)
2. NEsted MultiLine Comment [actually wont work as expected?!]
if you do this in C++....
/* blah /*blah blah blah*/ blah*/
the last blah will be visible to the compiler!!! (Inference- Multiline-Comment ends whenever */ is encountered, no matter where!!)NEsted MultiLine Comment
3. Size of various types (of C++) on 'Linux' Mint - (and same as in later versions of windows, and most PCs nowadays)
char - 1
int - 4 (and: short - 2, unsigned long - 8)
long long - 8
float - 4
double - 8 (and: long double - 16)
NOTE- All sizes in bytes
4. The Control Characters (for eg. newline and tab) require a BACKSLASH
*Seems obvious, but in cases where i dont do programming for some time, i get confused in the slash to be used... though i get it from the different colour in vim editor
5. Conversion of int* to char shows the error 'conversion of int* to char loses precision'
While conversion of int* to char* is OK.
6. Entering Out Of Range value in a declared variable...
In such a case, the variable will hold the maximum value it can hold, for example an int when given a very long number, it stores 2147483647 (ie. (2^31)-1).
7. Maximum value of unsigned variable = maximum value of signed variable
The thing I got surprised at was that, it stored the same number in both cases, let it be signed or unsigned! (size of int on my system is 4 bytes(32 bits) as on most)
//THINGS About ARRAYS
8. We cannot copy an array into another array of same type and same size by just simple assignment.
for eg. A=B; //where B is initialised, and both are in arrays of size 3
It shows 'error: invalid array assignment'
9. We can use initializer list to give values to elements of array, only when it is declared, after that we can't use it, it will show an error then...
for eg. int A[3]={34,5,4}; //is OK
BUT, int A[3];
A={34,5,4};
The second one shows 'error: invalid array assignment'
//XX XX XX//
10. I have posted this observation in another post also, ie. "Default return type of any function is int, nowadays atleast... and that main() be default returns 0, if return statement not typed"
But, I still expected it to be raised as a 'Warning' by the compiler
So... nor gcc nor g++ raises even any warning about missing return statement.
11. Entering Characters and MIXED data types when asked for an integer...
Case 1: Entered a,b,c etc. -> int variable stores 0
Case 2: Entered string Hi,Bye,etc -> int variable stores 0
//ACTUALLY, It ignores any succeeding character or integer, if first thing entered wasnt a number, but was an integer... So, for it Hi is same as H only!
Case 3: Entered 454d : Stores 454
//Ignores any other data type, in case first entered was some number, then it will just take any character as end of number (for eg. 'Enter key' is also a character)
Case 4: Entered 454d45: Stores 454
//Since it took any further character to be end of number (NOTE: In all cases i am saying number ended, actually the input hasnt ended, but i mean it will be treated like that later...)
Case 5: Enter f344, fsg45, d454fg, etc (ie. character at start) -> int variable stores 0
//Maybe since it just treated b, which will cause its value 0, and since being a character further things weren't even accounted for
12. 'long' and 'long long' have same size, ie. 8 bytes in g++ compiler
But, 'double' has 8 bytes, while 'long double' has 16 bytes
I used g++ to compile these on linux
1. Type casting of floating point numeral to integer (either automatic or by type casting)-
Conversion of floating point to integer is by taking the GIF (Greatest Integer Funtion) and NOT ROUNDING OFF
Greatest Integer Function(Maths,12th) it gives the integer part when the original number is written as integer+fractional part (where fractional part is less than 1 but positive)
2. NEsted MultiLine Comment [actually wont work as expected?!]
if you do this in C++....
/* blah /*blah blah blah*/ blah*/
the last blah will be visible to the compiler!!! (Inference- Multiline-Comment ends whenever */ is encountered, no matter where!!)NEsted MultiLine Comment
3. Size of various types (of C++) on 'Linux' Mint - (and same as in later versions of windows, and most PCs nowadays)
char - 1
int - 4 (and: short - 2, unsigned long - 8)
long long - 8
float - 4
double - 8 (and: long double - 16)
NOTE- All sizes in bytes
4. The Control Characters (for eg. newline and tab) require a BACKSLASH
*Seems obvious, but in cases where i dont do programming for some time, i get confused in the slash to be used... though i get it from the different colour in vim editor
5. Conversion of int* to char shows the error 'conversion of int* to char loses precision'
While conversion of int* to char* is OK.
6. Entering Out Of Range value in a declared variable...
In such a case, the variable will hold the maximum value it can hold, for example an int when given a very long number, it stores 2147483647 (ie. (2^31)-1).
7. Maximum value of unsigned variable = maximum value of signed variable
The thing I got surprised at was that, it stored the same number in both cases, let it be signed or unsigned! (size of int on my system is 4 bytes(32 bits) as on most)
//THINGS About ARRAYS
8. We cannot copy an array into another array of same type and same size by just simple assignment.
for eg. A=B; //where B is initialised, and both are in arrays of size 3
It shows 'error: invalid array assignment'
9. We can use initializer list to give values to elements of array, only when it is declared, after that we can't use it, it will show an error then...
for eg. int A[3]={34,5,4}; //is OK
BUT, int A[3];
A={34,5,4};
The second one shows 'error: invalid array assignment'
//XX XX XX//
10. I have posted this observation in another post also, ie. "Default return type of any function is int, nowadays atleast... and that main() be default returns 0, if return statement not typed"
But, I still expected it to be raised as a 'Warning' by the compiler
So... nor gcc nor g++ raises even any warning about missing return statement.
11. Entering Characters and MIXED data types when asked for an integer...
Case 1: Entered a,b,c etc. -> int variable stores 0
Case 2: Entered string Hi,Bye,etc -> int variable stores 0
//ACTUALLY, It ignores any succeeding character or integer, if first thing entered wasnt a number, but was an integer... So, for it Hi is same as H only!
Case 3: Entered 454d : Stores 454
//Ignores any other data type, in case first entered was some number, then it will just take any character as end of number (for eg. 'Enter key' is also a character)
Case 4: Entered 454d45: Stores 454
//Since it took any further character to be end of number (NOTE: In all cases i am saying number ended, actually the input hasnt ended, but i mean it will be treated like that later...)
Case 5: Enter f344, fsg45, d454fg, etc (ie. character at start) -> int variable stores 0
//Maybe since it just treated b, which will cause its value 0, and since being a character further things weren't even accounted for
12. 'long' and 'long long' have same size, ie. 8 bytes in g++ compiler
But, 'double' has 8 bytes, while 'long double' has 16 bytes
Comments
Post a Comment
You are free to leave any kind of suggestion, or improvement. It doesn't require you to sign in either.