Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 3203 of 3366
4K+ Views
The above symbols mean the following −int* - Pointer to int. This one is pretty obvious. int const * - Pointer to const int. int * const - Const pointer to int int const * const - Const pointer to const intAlso note that −const int * And int const * are the same. const int * const And int const * const are the same.If you ever face confusion in reading such symbols, remember the Spiral rule: Start from the name of the variable and move clockwise to the next pointer or type. Repeat until expression ends.
368 Views
First way is using a stringstream to read words seperated by spaces. This is a little limited but does the task fairly well if you provide the proper checks. example#include #include #include using namespace std; int main() { string str("Hello from the dark side"); string tmp; // A string to store the word on each iteration. stringstream str_strm(str); vector words; // Create vector to hold our words while (str_strm >> tmp) { // Provide proper checks here for tmp like if empty // ... Read More
3K+ Views
You should really be using a library to parsing CSV files in C++ as there are many cases that you can miss if you read files on your own. The boost library for C++ provides a really nice set of tools for reading CSV files. For example, example#include vector parseCSVLine(string line){ using namespace boost; std::vector vec; // Tokenizes the input string tokenizer tk(line, escaped_list_separator ('\', ', ', '\"')); for (auto i = tk.begin(); i!=tk.end(); ++i) vec.push_back(*i); return vec; } int main() { std::string line = "hello, from, ... Read More
8K+ Views
You can set clear and toggle bits using bitwise operators in C, C++, Python, and all other programming languages that support these operations. You also need to use the bitshift operator to get the bit to the right place.Setting a bitTo set a bit, we'll need to use the bitwise OR operator −Example#include using namespace std; int main() { int i = 0, n; // Enter bit to be set: cin >> n; i |= (1 > n; i ^= (1
813 Views
In C++, floating-point numbers are used to represent decimal values. The most commonly used floating-point types are float and double. These data types differ in their size, precision, and use cases. Understanding how to use and compare them correctly is important for accurate computations. Understanding Float and Double Precision The float is a 32-bit single-precision floating-point type that can store approximately 7 decimal digits, while double is a 64-bit double-precision type that offers about 15 to 16 digits of precision. Due to these differences, double is generally preferred for higher accuracy in scientific and financial calculations. Example: Printing ... Read More
1K+ Views
You can't access a local variable once it goes out of scope. This is what it means to be a local variable. Though, Let us look at an example where you MIGHT be able to access a local variable's memory outside its scope.Example#include int* foo() { int x = 3; return &x; } int main() { int* address = foo(); cout
17K+ Views
Singleton design pattern is a software design principle that is used to restrict the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. For example, if you are using a logger, that writes logs to a file, you can use a singleton class to create such a logger. You can create a singleton class using the following code −Example#include using namespace std; class Singleton { static Singleton *instance; int data; // Private constructor so that no objects can be created. ... Read More
4K+ Views
const_castcan be used to remove or add const to a variable. This can be useful if it is necessary to add/remove constness from a variable.static_castThis is used for the normal/ordinary type conversion. This is also the cast responsible for implicit type coersion and can also be called explicitly. You should use it in cases like converting float to int, char to int, etc.dynamic_castThis cast is used for handling polymorphism. You only need to use it when you're casting to a derived class. This is exclusively to be used in inheritence when you cast from base class to derived class.reinterpret_castThis is ... Read More
142 Views
You can find the current C standard documents on ANSI web store. https://webstore.ansi.org/RecordDetail.aspx?sku=INCITS%2FISO%2FIEC+9899-2012You can find the current C++ standard documents on the ISO C++ website for buying − https://www.iso.org/standard/68564.htmlThe working draft of the ISO C++ standard is also available on https://isocpp.org/std/the-standard
434 Views
A smart pointer is a class that wraps a 'raw' (or 'bare') C++ pointer. It is used to manage resources the pointer points to. For example, if the reference to that memory location is lost. It kind of acts like a garbage collector. There are multiple smart pointer types.You should almost always use a smart pointer. This is because the main pain point of using pointers is manual memory management and memory leaks. The smart pointer tries to get rid of both of these. If you don't want to do either of these in practice, you should use a smart ... Read More