Questions tagged [declaration]

Declaration is the part of the subprogram (procedure or function) which provides the protocol(header), but not the body of the subprogram.

3407 questions
1030
votes
27 answers

What is the difference between a definition and a declaration?

The meaning of both eludes me.
Maciek
  • 19,435
  • 18
  • 63
  • 87
958
votes
20 answers

What’s the difference between "Array()" and "[]" while declaring a JavaScript array?

What's the real difference between declaring an array like this: var myArray = new Array(); and var myArray = [];
Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
866
votes
12 answers

What is the meaning of 'const' at the end of a member function declaration?

What is the meaning of const in declarations like these? class foobar { public: operator int () const; const char* foo() const; };
user91111
662
votes
17 answers

Define a global variable in a JavaScript function

Is it possible to define a global variable in a JavaScript function? I want use the trailimage variable (declared in the makeObj function) in other functions. …
hamze
  • 7,061
  • 6
  • 34
  • 43
545
votes
18 answers

Why is volatile needed in C?

Why is volatile needed in C? What is it used for? What will it do?
thomas
408
votes
21 answers

Declaring multiple variables in JavaScript

In JavaScript, it is possible to declare multiple variables like this: var variable1 = "Hello, World!"; var variable2 = "Testing..."; var variable3 = 42; ...or like this: var variable1 = "Hello, World!", variable2 = "Testing...", variable3…
Steve Harrison
  • 121,227
  • 16
  • 87
  • 72
391
votes
5 answers

What is the 'open' keyword in Swift?

The ObjectiveC.swift file from the standard library contains the following few lines of code around line 228: extension NSObject : Equatable, Hashable { /// ... open var hashValue: Int { return hash } } What does open var mean in this…
Clashsoft
  • 11,553
  • 5
  • 40
  • 79
333
votes
10 answers

Meaning of = delete after function declaration

class my_class { ... my_class(my_class const &) = delete; ... }; What does = delete mean in that context? Are there any other "modifiers" (other than = 0 and = delete)?
Pat O'Keefe
  • 3,333
  • 3
  • 15
  • 5
316
votes
8 answers

Is it possible to declare two variables of different types in a for loop?

Is it possible to declare two variables of different types in the initialization body of a for loop in C++? For example: for(int i=0,j=0 ... defines two integers. Can I define an int and a char in the initialization body? How would this be done?
Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
295
votes
5 answers

What does "default" mean after a class' function declaration?

I've seen default used next to function declarations in a class. What does it do? class C { C(const C&) = default; C(C&&) = default; C& operator=(const C&) & = default; C& operator=(C&&) & = default; virtual ~C() { } };
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
290
votes
8 answers

What are forward declarations in C++?

At this link, the following was mentioned: add.cpp: int add(int x, int y) { return x + y; } main.cpp: #include int add(int x, int y); // forward declaration using function prototype int main() { using namespace std; cout…
Simplicity
  • 47,404
  • 98
  • 256
  • 385
263
votes
7 answers

Initializing multiple variables to the same value in Java

I'm looking for a clean and efficient method of declaring multiple variables of the same type and of the same value. Right now I have: String one = "", two = "", three = "" etc... But I'm looking for something like: String one,two,three = "" Is…
user83643
  • 2,901
  • 2
  • 17
  • 13
251
votes
20 answers

Cannot refer to a non-final variable inside an inner class defined in a different method

Edited: I need to change the values of several variables as they run several times thorugh a timer. I need to keep updating the values with every iteration through the timer. I cannot set the values to final as that will prevent me from updating the…
Ankur
  • 50,282
  • 110
  • 242
  • 312
215
votes
2 answers

How to initialize a vector in C++

I want to initialize a vector like we do in case of an array. Example int vv[2] = {12, 43}; But when I do it like this, vector v(2) = {34, 23}; OR vector v(2); v = {0, 9}; it gives an error: expected primary-expression before ‘{’…
Md Faisal
  • 2,931
  • 8
  • 29
  • 34
175
votes
12 answers

Isn't a semicolon (';') needed after a function declaration in C++?

I just recently took an intermediate programming test, and one of the questions I got wrong was as follows: A semicolon (';') is not needed after a function declaration. True or False. I chose "false" (and please correct me if I'm wrong because I…
Logan
  • 1,629
  • 2
  • 7
  • 6
1
2 3
99 100