Skip to content

Miscellaneous

  • oop
  • derived from c
  • c with classes, but now it's much more
  • low level access to memory

  • Advantages

    • fast
    • more low level access
  • Disadvantages
    • memory leaks
    • oop drawbacks, due to multiple inheritance
    • porting to other platform is time consuming

Common Mistakes

OOP in C++

  • Classes
    • templates for objects
    • when a class is instantiated it becomes a object
  • Object
    • instance of the class

FAQ and common misconceptions

  • C++ is C with classes
    • although this is correct but this does not means all the C features are available in C++ also
    • you should follow C++ standard and not something that works in a particular compiler
    • #include<bits/stdc++.h> this is g++ specific library, so if you use it on some other compiler it will not work.
    • other difference are in initialization of variable sized array, in g++ the declaration int a[v] = {0}; will work but it will not work in every compiler, because it is not in C++ specification. C++ don't support variable length arrays.
  • out of scope vector

  • how to create a variable sized array

Typecasting error

  • first store result in a variable then use it inside if else because of type conversions, note that size return unsigned numbers for all containers.
long n;
long temp;

// this will give -1 if n = temp*s.length()
long answer = n - temp * s.length() - 1; 

// this will give 18446744073709551615
cout << n - temp * s.length() - 1;

// reason because s.length() gives a unsigned number
  • data types limits in c++
data exact range approx
short int -32,768 to 32,767 -3E4 - 3E4
unsigned short int 0 to 65,535 0 - 6E4
unsigned int 0 to 4,294,967,295 0 - 4E9
int -2,147,483,648 to 2,147,483,647 -2E9 - 2E9
long int -2,147,483,648 to 2,147,483,647 -2E9 - 2E9
unsigned long int 0 to 4,294,967,295 0 - 4E9
long long int -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 -9E18 - 9E18
unsigned long long int 0 to 18,446,744,073,709,551,615 0 - 1E19
signed char -128 to 127 -1E2 - 1E2
unsigned char 0 to 255 0 - 2E2