w3resource

C++ programming Exercises practice with solution

What is C++ Programming Language?

C++ is a general-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation.

It was designed with a bias toward system programming and embedded, resource-constrained and large systems, with performance, efficiency and flexibility of use as its design highlights. Many vendors provide C++ compilers, including the Free Software Foundation, Microsoft, Intel, and IBM.

The best way we learn anything is by practice and exercise questions. We have started this section for those (beginner to intermediate) who are familiar with C++ programming.

Hope, these exercises help you to improve your C++ programming coding skills. Currently, following sections are available, we are working hard to add more exercises .... Happy Coding!

List of C++ Exercises

More to Come !

Popularity of Programming Language
Worldwide, Dec 2022 compared to a year ago:

`
Rank Change Language Share Trend
1 Python 28.34 % -1.0 %
2 Java 16.93 % -0.8%
3 Javascript 9.28 % +0.3%
4 C# 6.89 % -0.3%
5 C/C++ 6.64 % -0.3 %
6 PHP 5.19 % -1.0 %
7 R 3.98 % -0.1%
8 up arrow TypeScript 2.79 % +1.1%
9 up arrow Swift 2.23 % +0.6%
10 down arrow Objective-C 2.22% +0.1%
11 down arrow Go2.02% +0.7%
12 up arrow Rust 1.78 % +0.8%
13 down arrow Kotlin 1.71 % -0.0%
14 down arrow Matlab 1.61 % +0.0%
15 up arrow Ruby 1.12% +0.2%
16 down arrow VBA 1.08 % -0.1 %
17 Ada 0.96 % +0.2 %
18 up arrow Dart 0.85 % +0.4 %
19 down arrow Scala 0.69 % -0.0 %
20 up arrow Lua 0.65 % +0.3 %
21 down arrow Visual Basic 0.57 % -0.1 %
22 down arrow Abap 0.55 % +0.1 %
23 down arrow Perl 0.53 % +0.1 %
24 Groovy 0.36 % +0.0 %
25 Cobol 0.33 % +0.0 %
26 Haskell 0.25 % +0.0 %
27 up arrow Julia 0.24 % +0.0 %
28 down arrow Delphi/Pascal 0.2 % -0.0 %

Source : https://pypl.github.io/PYPL.html

TIOBE Index for November 2022

Nov 2022 Nov 2021 Change Programming Language Ratings Change
1 1 Python 17.18% +5.41%
2 2 C 15.08% +4.35%
3 3 Java 11.98% +1.26%
4 4 C++ 10.75% +2.46%
5 5 C# 4.25% -1.81%
6 6 Visual Basic 4.11% -1.61%
7 7 JavaScript 2.74% +0.08%
8 8 Assembly language 2.18% -0.34%
9 9 SQL 1.82% -0.30%
10 10 PHP 1.69% -0.12%
11 18 up arrow Go 1.15% -0.06%
12 15 up arrow R 1.14% -0.14%
13 11 down arrow Classic Visual Basic 1.10% -0.46%
14 17 up arrow Delphi/Object Pascal 1.08% -0.14
15 20 up arrow MATLAB 1.02% -0.15%
16 28 up arrow Objective-C 0.93% +0.39%
17 24 up arrow Scratch 0.88% +0.11%
18 14 up arrow Swift 0.87% -0.56%
19 13 down arrow Ruby 0.85% -0.59%
20 29 up arrow Rust 0.75% +0.21%

Source : https://www.tiobe.com/tiobe-index/



Share this Tutorial / Exercise on : Facebook and Twitter

C++ Programming: Tips of the Day

Fastest way to check if a file exist using standard C++/C++11,14,17/C?

Hese is a test program that ran each of these methods 100,000 times, half on files that existed and half on files that didn't.

#include <sys/stat.h>
#include <unistd.h>
#include <string>
#include <fstream>

inline bool exists_test0 (const std::string& name) {
    ifstream f(name.c_str());
    return f.good();
}

inline bool exists_test1 (const std::string& name) {
    if (FILE *file = fopen(name.c_str(), "r")) {
        fclose(file);
        return true;
    } else {
        return false;
    }   
}

inline bool exists_test2 (const std::string& name) {
    return ( access( name.c_str(), F_OK ) != -1 );
}

inline bool exists_test3 (const std::string& name) {
  struct stat buffer;   
  return (stat (name.c_str(), &buffer) == 0); 
}

Results for total time to run the 100,000 calls averaged over 5 runs,

      
Method	                          Time
exists_test0 (ifstream)            0.485s
exists_test1 (FILE fopen)	      0.302s
exists_test2 (posix access())      0.202s
exists_test3 (posix stat())        0.134s 

The stat() function provided the best performance on my system (Linux, compiled with g++), with a standard fopen call being your best bet if you for some reason refuse to use POSIX functions.

Ref : https://bit.ly/3CNphUq