What is the best way to declare and define global variables?



What is the best way to declare and define global variables?..

Answer / Pawan Kumar Sahu

Global variables are declared outside of any function. For variable declaration, you can simply write `extern type variableName;`, but for initialization, use `extern type variableName = value;` in a .cpp file.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What do you mean by “this” pointer?

1 Answers  


When volatile can be used?

3 Answers   Symphony,


Do class declarations end with a semicolon? Do class method definitions?

1 Answers  


Write a program to get the value of sin (x) using a library function , when x is given in degrees.

1 Answers  


Difference between overloaded functions and overridden functions

1 Answers  


What are associate containers?

1 Answers  


what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?

1 Answers  


What is the difference between "calloc" and "malloc"?

9 Answers   ADP,


int *p = NULL; printf("%1d",p) ; what will be the output of this above code?

3 Answers   Microsoft,


How do I download c++?

1 Answers  


If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?

1 Answers  


What is expression parser in c++

1 Answers   Mphasis,


Categories