Posts

What is a variable scope?

Scope of a variable Scope refers to the visibility of the variable. Broadly speaking it means in which region or which piece of code have access to that variable. There are generally two scopes of variables ·         Inside a function or a block which is called local variables, ·         Outside of all functions which is called global variables. Local Variables Variables that are declared inside a function or block are local variables. They can be used only by statements that are inside that function or block of code. Local variables are not known to functions outside their own. Following is the example using local variables: #include using namespace std ; int main () {    // Local variable declaration:    int a , b ;    int c ;    // actual initialization    a = 10 ;    b = 20 ;    c = a + b ; ...

Data types in c++

Variables in programming language are same as variables in mathematics, in a sense that their value also varies they are also defined in a similar fashion E.g. x = 5; here x is a variable which has a value 5 stored in it. Variables are used to reserve memory locations to store values. There are types of variables so information of different types can be stored on it. For example, int for storing integer and bool for storing Boolean value. Primitive Built-in Types C++ offer the programmer a rich assortment of built-in as well as user defined data types. Following table lists down seven basic C++ data types: Type Keyword Boolean bool Character char Integer int Floating point float Double floating point double The following table shows the variable type, how much memory it takes to store the value in memory, and what is maximum and minimum value which can be stored in such type of variables. ...

Types of variables in C++

A variable in programming is just like a variable in the mathematics, it is used to store some data in it, which we can manipulate in our code. Each variable in C++ has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable. Variables follow the same naming convention as we have discussed in identifiers tutorial. There are following basic types of variable in C++. Type Description bool Stores either value true or false. char It is used to store a byte of data. int The most natural size of integer for the machine. float A single-precision floating point value. double A double-precision floating point value. void Represents the absence of type. There are also some other types of variable...

Comments in C++

Comments are explanatory statements that are included in programs. All programming languages allow for some form of comments. Comments in C++ starts with “ // ” these two forward slashes indicate that these are comments and C++ compiler will ignore these lines. Comments are used to help others understand that part of the code or they can be used to explain some point or function of that piece of code. // This is a comment. int a = 5; //initializing a’s value with 5 A comment can also start with /* and ends with the */ this is also used for multiline comments. For example #include using namespace std ; int main () {          /*this program just          Prints Hello World */    cout << "Hello World" ;    return 0 ; } While the code above is compiled by the compiler, it will ignore the anything written between /* */. And will print following ...