Found 7197 Articles for C++

Where do I find the current C or C++ standard documents?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

278 Views

In this post you can get some details where you can buy and view free drafts of some current and past C/C++ standards.C DocumentsC11:198 CHF (https://www.iso.org/standard/57853.html)Publicly at (http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf)Wikipedia Link (https://en.wikipedia.org/wiki/C11_(C_standard_revision))C99:Cannot Purchase (https://www.iso.org/standard/29237.html)Publicly at (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf)Wikipedia Link (https://en.wikipedia.org/wiki/C99)C90, C89, ANSI C, Standard CWikipedia Page: (https://en.wikipedia.org/wiki/ANSI_C)C++ DocumentsC++14:198 CHF (https://www.iso.org/standard/64029.html)Based On (https://www.iso.org/standard/29237.html)Wikipedia Link (https://en.wikipedia.org/wiki/ANSI_C)C++11:Cannot Purchase (https://www.iso.org/standard/50372.html)Publicly at (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf)Wikipedia Link (https://en.wikipedia.org/wiki/C%2B%2B11)C++03Wikipedia Page: (https://en.wikipedia.org/wiki/C%2B%2B03)C++89Wikipedia Page: (https://en.wikipedia.org/wiki/C%2B%2B)Read More

When can I use a forward declaration in C/C++?

Ravi Ranjan
Updated on 02-Jun-2025 18:20:45

901 Views

A forward declaration informs the compiler that a class, function, or variable is declared earlier, but it will be defined later in the code. In this article, our task is to understand the forward declaration and when to use it. When is Forward Declaration Used in C/C++? The forward declaration can be used in C/C++ in the following cases: In C++, it is used for declaring a friend function. Using the forward declaration, we can reduce the header files that we include in the code. When ... Read More

C++ Program to Implement Segmented Sieve to Generate Prime Numbers Between Given Range

Ravi Ranjan
Updated on 07-May-2025 18:36:53

1K+ Views

The Segmented Sieve algorithm is used to find the prime numbers within a given range. Segmented Sieve first uses the Sieve of Eratosthenes algorithm to find the primes smaller than or equal to √(n). The idea of this algorithm is to divide the range [0 ... n-1] in different segments and compute primes in all segments one by one. In this article, we have a range defined from low to high. Our task is to implement the Segmented Sieve to find the prime numbers within the given range in C++. Example The following example generates all the prime numbers between ... Read More

C++ Program to Implement Sieve of Atkin to Generate Prime Numbers Between Given Range

Ravi Ranjan
Updated on 05-May-2025 18:42:43

610 Views

The Sieve of Atkin is a modern algorithm for finding all prime numbers up to a specified integer. It follows three simple steps to find the prime numbers. It uses three quadratic expressions that remove the composite numbers. After this, we remove the multiples of squares of already existing prime numbers and at the end, we return the prime numbers. In this article, we have set the limit to '30'. Our task is to implement the Sieve of Atkin method to generate all the prime numbers up to the limit in C++. Here is an example of prime numbers up ... Read More

Why isn't sizeof for a struct equal to the sum of sizeof of each member in C/C++?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

893 Views

The size of a struct type element taken by sizeof() is not always equal to the size of each individual member. Sometimes the compilers add some padding to avoid alignment issues. So the size may change. The padding is added when a structure member is followed by a member with a larger size or at the end of the structure. Different compiler has different types of alignment constraints. In C standard, the total alignment structure depends on the implementation.Case 1In this case the double z is 8-byte long, which is larger than x (4-byte). So another 4-byte padding is added. ... Read More

What are copy elision and return value optimization in C++?

George John
Updated on 30-Jul-2019 22:30:25

332 Views

The Copy Elision is also known as the Copy Omission. This is one of the compiler optimization technique. It avoids the unnecessary copying of objects. Almost any current compiler uses this Copy Elision technique.Let us see how it works by the help of one example code.Example Code#include using namespace std; class MyClass { public: MyClass(const char* str = "\0") { //default constructor cout

How can I profile C++ code running on Linux?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

475 Views

In Linux platform there are many great profiling tools for profiling C++ programs. Valgrind is one of them. It is widely used. It is a programming tool for memory debugging, memory leak detection, and profiling. We can use Valgrind by passing the binary to it and setting the tool to callgrind. First generate the binary by compiling the program$ g++ -o abc.cpp abcNow use valgrind to profile it$ valgrind --tool=callgrind ./abcThis will generate a file called callgrind.out.x. You can read this file using a tool called kcachegrind.If you're using gcc, you can use the inbuilt profiling tool, gprof. You can ... Read More

Why is iostream::eof inside a loop condition considered wrong?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

202 Views

The iostream::eof in a loop is considered as wrong because we haven’t reached the EOF. So it does not mean that the next read will succeed.When we want to read a file using file streams in C++. And when we use a loop to write in a file, if we check the end of file using stream.eof(), we are actually checking whether the file has reached end or not.Example Code#include #include using namespace std; int main() { ifstream myFile("myfile.txt"); string x; while(!myFile.eof()) { myFile >> ... Read More

C++ Program to Implement Sieve of eratosthenes to Generate Prime Numbers Between Given Range

Ravi Ranjan
Updated on 05-May-2025 18:42:30

3K+ Views

The Sieve of Eratosthenes algorithm is one of the most efficient ways to find prime numbers smaller than n when n is smaller than around 10 million. It follows a simple process of marking the multiples of already prime numbers as false i.e. non-prime numbers. In this article, we have a given number as 'num'. Our task is to find all the prime numbers less than or equal to num using the Sieve of Eratosthenes algorithm in C++. Example Here is an example to find prime numbers less than 10: Input: num = 10 Output: 2 3 5 7 ... Read More

C++ Program to Implement Wheel Sieve to Generate Prime Numbers Between Given Range

Ravi Ranjan
Updated on 05-May-2025 18:42:57

449 Views

The wheel Sieve method is used to find the prime numbers within a given range. Wheel factorization is a graphical method for manually performing a preliminary to the Sieve of Eratosthenes that separates prime numbers from composites. In this method, prime numbers in the innermost circle have their multiples in similar positions as themselves in the other circles, forming spokes of primes and their multiples. Multiple of these prime numbers in the innermost circle form spokes of composite numbers in the outer circles. In this article, we have set the limit to 100. Our task is to implement the ... Read More

Advertisements