C++ Articles - Page 705 of 719

Why can C++ templates only be implemented in the header file?

Ramu Prasad
Updated on 11-Feb-2020 10:14:53

904 Views

When you instantiate a template in C++, the compiler creates a new class. This class has all the places where you placed the template arguments replaced with the actual argument you pass to it when using it. For example −template class MyClass {    T foo;    T myMethod(T arg1, T arg2) {       // Impl    } };And somewhere in your program use this class, MyClass x;The compiler creates a new class upon encountering this for every type argument you pass it. For example, if you created 3 objects with different template arguments you'll get 3 classes, ... Read More

How to start object-oriented programming in C++?

Arjun Thakur
Updated on 02-Mar-2020 08:09:42

886 Views

Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which may contain data, in the form of attributes; and instructions to do things, in the form of methods.For example, a person is an object which has certain properties such as height, gender, age, etc. It also has certain methods such as move, talk, and so on.ObjectThis is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object.ClassWhen you define a class, you define a blueprint for an object. This doesn't actually ... Read More

What is the use of the '&' symbol in C++?

Sravani S
Updated on 07-Nov-2023 20:29:43

31K+ Views

The & symbol is used as an operator in C++. It is used in 2 different places, one as a bitwise and operator and one as a pointer address of operator.Bitwise ANDThe bitwise AND operator (&) compares each bit of the first operand to that bit of the second operand. If both bits are 1, the bit is set to 1. Otherwise, the bit is set to 0. Both operands to the bitwise AND operator must be of integral types. Example #include   using namespace std;   int main() {      unsigned short a = 0x5555;      // pattern 0101 ...      unsigned short b = 0xAAAA;      // pattern 1010 ...      cout

What are undefined reference/unresolved external symbol errors in C++?

Daniol Thomas
Updated on 23-Jun-2020 13:26:30

1K+ Views

As the name suggests, a symbol you declared was not defined by you. This may occur due to many cases. Let's have a look at three of them −You forgot to define the declared name. For example, you declared a function in a file and used it somewhere. But you did not provide its definition. Code −#include void foo(); int main() {    foo(); // Declared but not defined }You defined it but did not use the qualified name. Say you created a class with a method and defined that method but forgot using scope resolution to link that function ... Read More

C++11 Features Supported by Intel

Priya Pallavi
Updated on 30-Jul-2019 22:30:21

180 Views

The C++11 features supported by Intel are available as an official guide in their docs. You can check these features out on https://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler.

Difference between static, auto, global and local variable in C++

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

4K+ Views

There are two separate concepts here − scope, which determines where a name can be accessed - global and local storage duration, which determines when a variable is created and destroyed - static and auto Scope Local variables can be used only by statements that are inside that function or block of code. Local variables are not known to functions on their own. Example Live Demo #include using namespace std; int main () { // Local variable declaration: int a, b; int c; // actual initialization a = 10; b = 20; c = a + b; cout

What are local variables and global variables in C++?

Akansha Kumari
Updated on 04-Jun-2025 13:34:59

9K+ Views

In C++, the scope defines the region within which a variable can be accessed. So, if broadly speaking, there are three main places where variables can be declared and accessed: Inside a function or a block, which are called local variables. In the definition of function parameters, which are called formal parameters. Outside of all functions, which are called global variables. Local Variables Local variables are the variables that are defined inside a function, method, or block of code within curly braces {}. These variables cannot be ... Read More

What are global variables in C++?

Lakshmi Srinivas
Updated on 11-Feb-2020 09:57:02

8K+ Views

Global variables are defined outside of all the functions, usually on top of the program. The global variables will hold their value throughout the lifetime of your program.A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration. Example#include using namespace std; // Global variable declaration: int g; int main () {    // Local variable declaration:    int a, b;    a = 10;    b = 20;    g = a + b;    cout

What are local variables in C++?

Akansha Kumari
Updated on 15-Jul-2025 17:31:11

536 Views

The variables, which are declared inside a function, block or method are known as local variables in C++. Their scope is limited to that function or block and can be accessed and used only within the area or scope they are defined. You cannot access or use them outside their scope. This is mainly used to prevent conflicts with other variables in other parts of the program and to efficiently manage memory. Key Characteristics of Local Variables Scope Limited : These variables are declared inside block or scope (usually {}) and are only visible and used ... Read More

How many keywords are there in C++?

Rishi Raj
Updated on 30-Jul-2019 22:30:21

4K+ Views

There are a total of 95 reserved words in C++. The reserved words of C++ may be conveniently placed into several groups. In the first group, we put those that were also present in the C programming language and have been carried over into C++. There are 32 of these.There are another 30 reserved words that were not in C, are therefore new to C++There are 11 C++ reserved words that are not essential when the standard ASCII character set is being used, but they have been added to provide more readable alternatives for some of the C++ operators, and ... Read More

Advertisements