
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do we initialize a variable in C++?
You can initialize a variable using the assignment operator or use its constructor when initializing it. For example,
int i = 0; MyClass instance(1, "Hello");
It will be automatically initialized if
- It's a class/struct instance in which the default constructor initializes all primitive types; like MyClass instance;
- You use array initializer syntax, e.g. int a[10] = {} (all zeroed) or int a[10] = {1,2}; (all zeroed except the first two items: a[0] == 1 and a[1] == 2)
- It is a global/extern variable
- It is defined static
- Related Questions & Answers
- Can we initialize blank final variable in Java
- How to initialize const member variable in a C++ class?
- How do we declare variable in Python?
- How do we use enum keyword to define a variable type in C#?
- How do you initialize jagged arrays in C#?
- How do we initialize an array within object parameters in java?
- How do we print a variable at the MongoDB command prompt?
- How do we set the Java environment variable in cmd.exe?
- How can we initialize a boolean array in Java?
- How to initialize a data frame with variable names in R?
- How do we create a structure in C#?
- How do we do variable formatting using the <var> tag in HTML?
- How many ways are there to initialize a final variable in java?
- How do you declare, initialize and access jagged arrays in C#?
- How to initialize a vector in C++?
Advertisements