GithubHelp home page GithubHelp logo

kameshkotwani / cpp-cheat-sheet Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 11 KB

A simple README file that contains valuable information about C++ data types, their max-values, common-functions, and much more.

cpp-cheat-sheet's Introduction

C++ Reference Cheat-Sheet

Common Data Types

data type bits Range
int 32-bits -2,147,483,647 to 2,147,483,647
INT_MAX 32-bits 2,147,483,647 (constant)
INT_MIN 32-bits -2,147,483,647 (constant)
char 8-bits, 1-byte -127 to 127

Useful Tips

1. To check for Integer overflow

  • we have to define #define INT_MIN (-INT_MAX-1) due to this Stack-Overflow-Boolean-Issue.
  • check if the result is getting overflow using this parameter if(result>INT_MAX/10 || result<INT_MIN/10) return false or return 0.

2. To check how much time the execution took place:

  • Add this code snippet at the end of main function: cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";

3. To watch any variable while debugging

  • #define watch(x) cout << (#x) << " is " << (x) << "\n"

4. To calculate GCD use built-in function

  • __gcd(x,y); there are two underscores _ _ not one

5. make cin and cout faster

  • `ios::sync_with_stdio(false); you cannot use printf and scanf

6. Incredible use of auto

  • auto i=10; will automatically assign int.
  • auto k=20LL; will automatically assign long long
  • auto z=1.0; will automatically assign double
  • auto s="somestring;" will automatically assign string

Bit Magic Techniques

1.


Math Functions

Function Description
double cos(double) Takes an angle (as a double) and returns the cosine.
double sin(double) Takes an angle (as a double) and returns the sine.
double tan(double) Takes an angle (as a double) and returns the tangent.
double log(double) Takes a number and returns the natural log (base-e) of that number.
double pow(double) The first is a number you wish to raise and the second is the power youwish to raise it to.
double sqrt(double) Returns square-root of the number.
int abs(int) Returns the absolute value.
double fabs(double) Returns the absolute value of any decimal number. (eg, 1,1.56,-3.99).
double floor(double) Returns the number less than or equal to the number passed.

STL Containers and Functions

Under Construction.

cpp-cheat-sheet's People

Contributors

kameshkotwani avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.