C++

Topic: Variable

Explain about Initialization of variables ?

When declaring a regular local variable, its value is by default undetermined. But you may want a variable to store a concrete value at the same moment that it is declared. In order to do that, you can initialize the variable. There are two ways to do this in C++:The first one, known as c-like initialization, is done by appending an equal sign followed by the value to which the variable will be initialized:type identifier = initial_value ;For example, if we want to declare an int variable called a initialized with a value of 0 at the moment in which it is declared, we could write:int a = 0;The other way to initialize variables, known as constructor initialization, is done by enclosing the initial value between parentheses (()):type identifier (initial_value) ;For example:int a (0); Both ways of initializing variables are valid and equivalent in C++.// initialization of variables#include <iostream>using namespace std;int main (){  int a=5;               // initial value = 5  int b(2);              // initial value = 2  int result;            // initial value undetermined  a = a + 3;  result = a - b;  cout << result;  return 0;}output:6

Browse random answers:

Scope of variables
Explain about Initialization of variables ?
Explain about Variable Declaration in C++ ?
Explain about Variable Initialization in C++:
Explain about Initializing Local and Global Variables ?
Explain about Global Variables ?
Explain about Calculations and variables ?
Why global variables are evil ?
How to store letters in a variable?
declaring floating-point type variables
What are variable declaration in c++ syntax ?
Write a function using reference variables as arguments to swap the values of a pair of integers?
How to access change a variable using pointer in C++?
Write a program to declare two integer , one float variables and assign 10, 15, and 12.6 to them respectively. It then prints these values on the screen.
What is a Variable?
What is an algorithm (in terms of the STL/C++ standard library)?
what are auto static variables and auto extern variables?
How many ways are there to initialize an int with a constant?
How do you decide which integer type to use?
How is static variable stored in the memory?( if there are 2 functions in a file,and the static variable name is same (ex var) in both the function. how is it keep seperately in the memory).
What can I safely assume about the initial values of variables which are not explicitly initialized?
What?s the auto keyword good for?
What is the difference between declaration and definition?
How variable declaration in c++ differs that in c?
What is difference between followin intialization.int iVar1;int iVar2 = int();and which one of two should we prefer always and why?
Are private class-level variables inherited?
Are there any new intrinsic (built-in) data types?
I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?
When you inherit a protected class-level variable, who is it available to?
What is a node class in c++?
What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.
Explain about Variables Data Types ?
Explain about Fundamental data types ?
Explain about Declaration of variables ?