Skip to main content

More_Inferences_in_C++(1Aug'19-16thOct'19)

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

Comments

Popular posts from this blog

Using 'ls' command as a replacement of 'find'

Advantage over find - Actually not probably in terms of speed, but... only point of this is that it's an observation, but... you can do like 'search only in' */*/*Programs* , /*/*Programs*/* , this may compensate the extra time took by using two commands 1. To search in current folder only (1 level... only this folder, no subfolder)     Type... ls | grep Search_Term 2. To search in current folder only (till level 2... this folder + subfolder)     Type... ls * | grep Search_Term #ls and ls * are NOT same! 3. To search in current folder only (till level 3... this folder + subfolder + subfolder)     Type... ls */* | grep Search_Term 4. To search in current folder only (till level 4... this folder + subfolder + subfolder + subfolder)     Type... ls */*/* | grep Search_Term ... and so on... FORMULA - To search till 'n' level (considering current folder as 1)... go till (n-1) stars If wanting to search whole disk... better type star...

LudO - The Game

/* Programmer - Aditya Gupta (Techy15) Language - C++ Program - LudO - The Game */ /* PLANS- Add functionality for name of player */ //IMP NOTE - See all notes, written in this form "//NOTE..." //NOTE- Mark 'R','G','B','Y' for gotis, ignore doubling for now //NOTE- Settings will have options: change default game play order(ie RBYG), change/give names to each colour //NOTE- Add code in case of attacks //NOTE- Add stops, and ways to show them distinct from others {may require graphics.h} #include<iostream> /* #include<fstream>    To be used in case save & resume to be used*/ #include<cstdio> #include<cstdlib> using namespace std; //Changes on 16th Oct //Show gotis as R1, R2... and ask user to enter string R1 or whatever // // Place within appropriate block ...     short diethrow(){     int fl=1; //holds 0 if decnum is 0     while(fl==0) { char *temp;     ...