Found 7346 Articles for C++

When is a semicolon after } mandated in C++ Program?

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

2K+ Views

A semicolon after a close brace is mandatory if this is the end of a declaration. In case of braces, they have used in declarations of class, enum, struct, and initialization syntax. At the end of each of these statements, we need to put a semicolon. For example, class X {}; // same declaration for struct as well enum Y {}; int z[] = {1, 2}; A semicolon by itself is an empty statement, and you'll be able to add additional ones anywhere a statement is legal. Therefore it might be legal to place a ... Read More

Why is sizeof() implemented as an operator in C++?

Nancy Den
Updated on 11-Feb-2020 05:56:32

110 Views

sizeof is not a real operator in C++. It is merely special syntax that inserts a continuing equal to the size of the argument. sizeof doesn’t want or have any runtime support. Sizeof cannot be overloaded because built-in operations, such as incrementing a pointer into an array implicitly depends on it.The C standard specifies that sizeof should be implemented as an operator. In most compilers, the value of sizeof is substituted by a constant equal to it at the compile time itself.example#include using namespace std; int main() {    cout

Write a C++ Program without Semicolons?

Anjana
Updated on 11-Feb-2020 05:55:11

302 Views

There are multiple ways to write a C++ program without semicolons. Note that doing this is very bad practice and should never be used in real code. This is presented just as informational content. The easiest way to write a C++ Program without Semicolons is using if statements. Almost all statements in C++ can be treated as expressions. So, if we place the statement inside an if statement with a blank pair of parentheses, we don’t have to end it with a semicolon anymore. For example, Example#include int main() {    if (int N = 1) {       ... Read More

Difference between Relational operator(==) and std::string::compare() in C++

Rishi Rathor
Updated on 11-Feb-2020 05:52:44

243 Views

There is only one difference between the relational operator == and std::string::compare(). That is the return value. Internally, string::operator==() is using string::compare()Relational operator(==) returns a boolean just signifying whether the 2 strings are equal or not while compare returns an integer that signifies how the strings relate to each other.To elaborate on the use cases, compare() can be useful if you're interested in how the two strings relate to one another (less or greater) when they happen to be different. For example, Example#include using namespace std; int main() {    string s1 = "Tutorials Point";    string s2 = ... Read More

C++ Program Structure

Ayyan
Updated on 11-Feb-2020 05:49:42

838 Views

The best way to learn a programming language is by writing programs. Typically, the first program beginners write is a program called "Hello World", which simply prints "Hello World" to your computer screen. Although it is very simple, it contains all the fundamental components C++ programs have. Let's look at the code for this program −#include int main() {    std::cout

C++ Relational and Equality Operators

Srinivas Gorla
Updated on 11-Feb-2020 05:40:45

2K+ Views

In C Programming, the values hold on in 2 variables will be compared exploitation following operators and relation between them will be determined. These operators are called relational operators. Various C++ relational operators available are-OperatorsDescription>Greater than>=Greater than or equal to

Semicolons in C++

Paul Richard
Updated on 19-Jun-2020 05:27:03

808 Views

According to the ISO C++ specifications, The lexical representation of C++ programs includes a number of preprocessing tokens which are used in the syntax of the preprocessor or are converted into tokens for operators and punctuators. The semicolon is a punctuator in C++.A semicolon character is at the end of the following parts of a C++ grammar (not necessarily a complete list) −an expression-statementa do/while iteration-statementthe various jump-statementsthe simple-declarationThese are all part of the C++ grammar. You can read more about these statements in the ISO C++ specification.

Explicit type casting operator in C++

Daniol Thomas
Updated on 11-Feb-2020 05:33:34

495 Views

A type cast provides a method for explicit conversion of the type of an object in a specific situation. It can be used as a unary expression −( type-name ) cast-expressionThe compiler treats cast-expression as type type-name after a typecast has been made. Casts are used to convert objects of any scalar kind to or from the other scalar type. Explicit type casts are constrained by the same rules that determine the effects of implicit conversions. Additional restraints on casts could result from the actual sizes or representation of specific types example#include using namespace std; int main() {    float x ... Read More

Conditional ternary operator ( ?: ) in C++

Abhinanda Shri
Updated on 11-Feb-2020 05:30:35

490 Views

The conditional operator (? :) is a ternary operator (it takes three operands). The conditional operator works as follows −The first operand is implicitly converted to bool. It is evaluated and all side effects are completed before continuing.If the first operand evaluates to true (1), the second operand is evaluated.If the first operand evaluates to false (0), the third operand is evaluated.The result of the conditional operator is the result of whichever operand is evaluated — the second or the third. Only one of the last two operands is evaluated in a conditional expression. The evaluation of the conditional operator ... Read More

What are C++ Manipulators (endl, setw, setprecision, setf)?

Rama Giri
Updated on 11-Feb-2020 05:28:21

3K+ Views

Stream Manipulators are functions specifically designed to be used in conjunction with the insertion () operators on stream objects, for example −std::cout

Advertisements