Found 9326 Articles for Object Oriented Programming

How to define a variable in C++?

Paul Richard
Updated on 11-Feb-2020 07:50:55

159 Views

To define a variable in  C++, you need to use the following syntax −Syntaxdatatype variable_name;You need to know what type of data is your variable is going to hold and what it will be called. The variable name has constraints on what you can name it. Following are the rules for naming variables −Variable names in C++ can range from 1 to 255 characters.All variable names must begin with a letter of the alphabet or an underscore(_).After the first initial letter, variable names can also contain letters and numbers.  Variable names are case sensitive.No spaces or special characters are allowed.You ... Read More

How to declare a variable in C++?

Monica Mona
Updated on 11-Feb-2020 08:01:15

456 Views

In C++, declaration and definition are often confused. A declaration means (in C) that you are telling the compiler about type, size and in case of function declaration, type and size of its parameters of any variable, or user-defined type or function in your program. No space is reserved in memory for any variable in case of a declaration.The Definition on the other hand means that in additions to all the things that declaration does, space is additionally reserved in memory. You can say "DEFINITION = DECLARATION + SPACE RESERVATION".Following are examples of declarations −extern int a;       ... Read More

How to define an enumerated type (enum) in C++?

Kumar Varma
Updated on 11-Feb-2020 07:47:54

273 Views

An enumerated type declares an optional type name and a set of zero or more identifiers that can be used as values of the type. Each enumerator is a constant whose type is the enumeration. For example, if you are creating an application that has a fixed number of types for some variable. For example, let's say gender, it can be of three types male, female and others. You can define and use an enum like −#include using namespace std; enum Gender {MALE, FEMALE, OTHERS}; int main() {    Gender gen = Gender.FEMALE;    return 0; }By default, the value ... Read More

What are enumerated data types in C++?

Sharon Christine
Updated on 11-Feb-2020 07:42:19

680 Views

An enumerated type declares an optional type name and a set of zero or more identifiers that can be used as values of the type. Each enumerator is a constant whose type is the enumeration. For example, if you are creating an application that has a fixed number of types for some variable. For example, let's say gender, it can be of three types male, female and others. You can define and use an enum like −#include using namespace std; enum Gender {MALE, FEMALE, OTHERS}; int main() {    Gender gen = Gender.FEMALE;    return 0; }By default, the value ... Read More

What is typedef declarations in C++?

Fendadis John
Updated on 11-Feb-2020 07:35:59

338 Views

The typedef keyword in C++ can be used to give a type a new name. For example, you can give a new name of BYTE to unsigned characters −typedef unsigned char BYTE;After this type definition, the identifier BYTE can be used as an abbreviation for the type unsigned char, for example −BYTE  b1, b2;This will declare 2 variables b1 and b2 of type unsigned char. Typedefs are really useful when you have huge names due to namespaces, class names, etc. For example, if you want a variable of type std::vector::iterator multiple times throughout your program. You can just rename it ... Read More

What type of comments does C++ support?

Samual Sam
Updated on 11-Feb-2020 07:33:15

196 Views

Program comments are explanatory statements that you can include in the C++ code. These comments help anyone reading the source code. All programming languages allow for some form of comments.C++ supports single-line and multi-line comments. All characters available inside any comment are ignored by C++ compiler.Single line commentsTo create a single line comment, we use the // notation. Wherever you want to start the comment, start it with //. For example,// This is a comment cout

What are fundamental data types in C++ programming?

Rama Giri
Updated on 11-Feb-2020 07:28:40

2K+ Views

A fundamental or primitive type is a data type where the values that it can represent have a very simple nature (a number, a character or a truth-value); the primitive types are the most basic building blocks for any programming language and are the base for more complex data types.C++ has the following primitive data types −S.NoTypeDescription1boolStores either value true or false.2charTypically a single octet (one byte). This is an integer type.3intThe most natural size of an integer for the machine.4floatA single-precision floating point value.5doubleA double-precision floating point value.6voidRepresents the absence of type.Read More

What are primitive data type in C++?

Fendadis John
Updated on 11-Feb-2020 07:19:29

4K+ Views

A primitive type is a data type where the values that it can represent have a very simple nature (a number, a character or a truth-value); the primitive types are the most basic building blocks for any programming language and are the base for more complex data types.C++ has the following primitive data types −S.NoTypeDescription1boolStores either value true or false.2charTypically a single octet (one byte). This is an integer type.3intThe most natural size of an integer for the machine.4floatA single-precision floating point value.5doubleA double-precision floating point value.6voidRepresents the absence of type.

What does 'using namespace std' mean in C++?

Moumita
Updated on 30-Jul-2019 22:30:21

11K+ Views

Consider a situation, when we have two persons with the same name, Piyush, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in a different area or their mother’s or father’s name, etc.The same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of ... Read More

Whitespace in C++

V Jyothi
Updated on 11-Feb-2020 06:48:24

7K+ Views

Whitespace is a term that refers to characters that are used for formatting purposes. In C++, this refers primarily to spaces, tabs, and (sometimes) newlines. The C++ compiler generally ignores whitespace, with a few minor exceptions. For example, all the 4 lines below mean the same thing −cout

Advertisements