C++ Productivity Hacks

C++ Productivity Hacks

1. Master Header File

#include <bits/stdc++.h>

2. Faster I/O Operations

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

3. Macros for Debugging

#define deb(x) cout << #x << " : " << x << "\n"

4. Number of Digits

int number = 12345;
int digits = floor(log10(number) + 1); // 5

5. Swap Two Numbers

int a = 10;
int b = 20;
swap(a, b); // 20 10

6. Number of Set Bits

int n = 15;
int setBit = __builtin_popcount(n); // 4

7. Auto Keyword

vector<int> v{1, 2, 3, 4, 5};
for (auto x : v)
  cout << x << " "; // 1 2 3 4 5

8. Inbuilt GCD Function

int x = 12;
int y = 16;
int gcd = __gcd(x, y); // 4

9. Lambda Function

auto add = [](int x, int y) {
  return x + y;
};
int sum = add(10, 20); // 30

10. Accumulate Function

int sum = 10;
int arr[] = {20, 30, 40};
sum = accumulate(arr, arr + 3, sum); // 100

Tip: Use “\n” instead of endl;


Pooja Mishra

Mentoring people how to make better career and live the life at fullest. Software Developer.

3 年

good information

Bhavya Jain

SDE-2 @JP Morgan Chase & Co. || Freelancer || Former - SDE Intern : Animall, Zorp || Frontend Web Developer || Documenting Software Development

3 年

Informative!

要查看或添加评论,请登录

Jeevan Joshi的更多文章

  • 50 Mathematical Concepts for Programming

    50 Mathematical Concepts for Programming

    The sum of natural numbers: The formula for the sum of the first n natural numbers is n(n+1)/2. This formula can be…

    2 条评论
  • Git - Source Code Manager

    Git - Source Code Manager

    Git Git is a tool that is used for managing the source code of a software project. It allows multiple developers to…

    3 条评论
  • “Hello, World!” in 10 different Programming Languages.

    “Hello, World!” in 10 different Programming Languages.

    “Hello, World!” is the very first program from which every programmer begins their programming journey. Now, We also…

    2 条评论
  • Top 50 C Programming Interview Questions and Answers

    Top 50 C Programming Interview Questions and Answers

    Q1. You know what are Increment and Decrement operators correct? What I want to know is how increment and decrement…

    1 条评论
  • 10 TOP 10

    10 TOP 10

    (I) Top 10 Sites for Career Enhancement:- 1. #LinkedIn 2.

社区洞察

其他会员也浏览了