Found 33676 Articles for Programming

What is the difference between new/delete and malloc/ free in C/ C++?

Arjun Thakur
Updated on 25-Jun-2020 10:07:58

2K+ Views

new/ deleteThe new operator requests for the memory allocation in heap. If the sufficient memory is available, it initializes the memory to the pointer variable and returns its address.The delete operator is used to deallocate the memory. User has the privilege to deallocate the created pointer variable by this delete operator.Here is an example of new/delete operator in C++ language,Example Live Demo#include using namespace std; int main () {    int *ptr1 = NULL;    ptr1 = new int;    float *ptr2 = new float(299.121);    int *ptr3 = new int[28];    *ptr1 = 28;    cout

What is the type of string literals in C/ C++?

Ankith Reddy
Updated on 25-Jun-2020 10:08:32

290 Views

The string literals are the set of characters which is enclosed in double quotes(“ “). Wide-string literals are prefixed with L always.Types of string literals −Sr.No.String Literals & Description1“ “Unprefixed string literal2L” “Wide-string literal3u8” “UTF-8 encoded string literal4u” “UTF-16 encoded string literal5U” “UTF-32 encoded string literal6R” “Raw string literalHere is an example of string literal in C++ language,Example Live Demo#include #include #include using namespace std; int main() {    wchar_t s[] = L"hello world!";    wcout

Why are global variables bad in C/C++?

Tapas Kumar Ghosh
Updated on 02-May-2025 18:00:43

3K+ Views

Global variables are declared and defined outside any function in the program. They hold their values throughout the lifetime of the program and are accessible throughout its execution. When we use our non-constant global variable in our programs, it becomes harder to manage. So, it is better to use local variables because of specific functions and easier understanding. You can use the prefix g_ for global variable names to avoid naming conflicts and to indicate that the variable is global. There is another way to encapsulate the global variable by defining the variable static. Therefore, these are the reasons behind ... Read More

What are the new changes introduced in C++11?

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

228 Views

C++11 is a version of standard C++ language. It was approved by International Organization for Standardization (ISO) on 12 August 2011 then C++14 and C++17. C++11 makes several additions to the core language. There are some of the new changes introduced in C++11 − nullptr − In the previous nullptr, zero used to be the value and it had a drawback of implicit conversion to integral value. The null pointer literal is represented by std::nullptr_t. In this nullptr, no implicit conversion exists. Lambdas − The lambda expression allows to define functions locally. Anonymous functions are known as lambda. We ... Read More

How to print out the contents of a vector in C++?

Chandu yadav
Updated on 14-Feb-2025 18:05:07

35K+ Views

Vectors are similar to the dynamic arrays but vectors can resize. They are sequence containers that can change their size according to the insertion or deletion of elements. Containers are the objects which holds the data of same type. Vectors may allocate some extra storage for the future growth of elements in the vector. Its elements are stored in the contiguous memory. The data is entered at the end of vector. In this article, we will show you how to print the contents of a vector in C++. Example Scenario: std::vector vec = {10, 20, 30, 40, 50}; You ... Read More

Do you think operator < is faster than <= in C/C++?

Arjun Thakur
Updated on 25-Jun-2020 09:45:25

1K+ Views

No, the operator < takes same time to execute as operator

List of C++ IDEs for Linux

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

416 Views

The following are some of C++ IDEs for linux − Eclipse Galileo with CDT Plugin Eclipse is a well-known open source and cross platform IDE. It provides full functional C/C++ IDE with the following features − Code editor with support for syntax highlighting Support for folding and hyperlink navigation Source code refactoring plus code generation Tools for visual debugging such as memory, registers etc. NetBeans IDE NetBeans is free, open source and popular IDE for C/C++. These are some of its features − Support for automatic packaging of compiled application into .tar, .zip and many more archive ... Read More

What is the difference between printf() and cout in C++?

Tapas Kumar Ghosh
Updated on 21-Apr-2025 18:01:01

3K+ Views

Both printf() and Cout are used to display the output format in C and C++ respectively. Each function has its syntax and characteristics that are based on user needs and preferences. In this article, we will learn the difference between print () and cout in a detailed manner. What is printf() in C? The printf() function is mainly used in C language. It is a formatting function that prints to the standard out. It prints to the console and takes a format specifier to print. It returns an integer value. It is not type-safe in input parameters. It can be ... Read More

How do I convert a char to an int in C and C++?

Tapas Kumar Ghosh
Updated on 04-Jun-2025 14:12:57

25K+ Views

In C/C++, char represents a single character, whereas int is an integer that can store both positive and negative values, but not fractional or decimal values. If you are given a character and want to convert it into an integer, it is easy and can be achieved with the different approaches. In this article, we will learn how we can convert a given character to an integer with different approaches. The following are some of the ways to convert a character to an integer: Using sscanf() Function Using atoi() Function ... Read More

#pragma Directive in C/C++

Ankith Reddy
Updated on 25-Jun-2020 09:50:00

3K+ Views

The preprocessor directive #pragma is used to provide the additional information to the compiler in C/C++ language. This is used by the compiler to provide some special features.Here is the syntax of #pragma directive in C/C++ language, #pragma token_nameThe table of some of #pragma directives in C/C++ language is given as follows, Sr.No.#pragma Directives & Description1#pragma startupBefore the execution of main(), the function specified in pragma is needed to run.2#pragma exitBefore the end of program, the function specified in pragma is needed to run.3#pragma warnUsed to hide the warning messages.4#pragma GCC dependencyChecks the dates of current and other file. If ... Read More

Advertisements