Declaration is the part of the subprogram (procedure or function) which provides the protocol(header), but not the body of the subprogram.
Questions tagged [declaration]
3407 questions
49
votes
5 answers
Why doesn't C# let you declare multiple variables using var?
Given the following:
// not a problem
int i = 2, j = 3;
so it surprises me that this:
// compiler error: Implicitly-typed local variables cannot have multiple declarators
var i = 2, j = 3;
doesn't compile. Maybe there is something I don't…

aarona
- 35,986
- 41
- 138
- 186
49
votes
8 answers
Java: define terms initialization, declaration and assignment
I find the defs circular, the subjects are defined by their verbs but the verbs are undefined! So how do you define them?
The Circular Definitions
initialization: to initialize a variable. It can be done at the time of
declaration.
assignment: to…

hhh
- 50,788
- 62
- 179
- 282
49
votes
2 answers
Getting error: ISO C++ forbids declaration of with no type
I'm getting the following errors:
ISO C++ forbids declaration of ttTreeInsert with no type
ISO C++ forbids declaration of ttTreeDelete with no type
ISO C++ forbids declaration of ttTreePrint with no type
prototype for int ttTree::ttTreePrint() does…

user2264035
- 565
- 1
- 7
- 13
49
votes
5 answers
what is the difference between function declaration and signature?
In C or C++ what is the difference between function declaration and function signature?
I know something of function declaration but function signature is totally new to me. What is the point of having the concept of function signature? What are the…

Tim
- 1
- 141
- 372
- 590
48
votes
2 answers
Declarations in C++
From what I have understood, declarations/initializations in C++ are statements with 'base type' followed by a comma separated list of declarators.
Consider the following declarations:
int i = 0, *const p = &i; // Legal, the so-called base type is…

stillanoob
- 1,279
- 2
- 16
- 29
48
votes
3 answers
How to add constructors/destructors to an unnamed class?
Is there a way to declare a constructor or a destructor in an unnamed class? Consider the following
void f()
{
struct {
// some implementation
} inst1, inst2;
// f implementation - usage of instances
}
Follow up question : The…

Nikos Athanasiou
- 29,616
- 15
- 87
- 153
47
votes
3 answers
The first snippet below compiles, but the second doesn't. Why?
The snippet below compiles (demo):
struct A{ int i = 10; };
int main() {
struct A{ int i = 20; };
struct A;
struct A a;
}
But this doesn't:
struct A{ int i = 10; };
int main() {
// struct A{ int i = 20; };
struct A;
struct…

João Afonso
- 1,934
- 13
- 19
47
votes
8 answers
Assign multiple values to array in C
Is there any way to do this in a condensed form?
GLfloat coordinates[8];
...
coordinates[0] = 1.0f;
coordinates[1] = 0.0f;
coordinates[2] = 1.0f;
coordinates[3] = 1.0f;
coordinates[4] = 0.0f;
coordinates[5] = 1.0f;
coordinates[6] =…

UnstableFractal
- 1,403
- 2
- 15
- 29
45
votes
3 answers
Dereferencing a pointer in a 'for' loop initializer creates a segmentation fault
I'm having a problem using pointers in a for loop. In my for loop initializer, I dereference an int pointer and give it a value of '0'. When I use that dereferenced pointer in the loop I get a segmentation fault, and I don't understand why. I am…

Mark R
- 569
- 3
- 6
44
votes
7 answers
How do I declare several variables in a for (;;) loop in C?
I thought one could declare several variables in a for loop:
for (int i = 0, char* ptr = bam; i < 10; i++) { ... }
But I just found out that this is not possible. GCC gives the following error:
error: expected unqualified-id before 'char'
Is it…

bodacydo
- 75,521
- 93
- 229
- 319
43
votes
3 answers
Function parameter types and =>
What exactly that declaration of method parameter means:
def myFunc(param: => Int) = param
What is meaning of => in upper definition?

PrimosK
- 13,848
- 10
- 60
- 78
42
votes
4 answers
Is it legitimate in modern C++ to define a return variable in the function declaration?
I found a strange piece of C++ grammar on CodeSignal:
string r, longestDigitsPrefix(string s)
{
for(auto const c : s)
{
if(isdigit(c))
r += c;
else
break;
}
return r;
}
The first line is defining string r…

Harry
- 709
- 1
- 6
- 16
42
votes
4 answers
Comma omitted in variadic function declaration in C++
I am used to declaring variadic functions like this:
int f(int n, ...);
When reading The C++ Programming Language I found that the declarations in the book omit the comma:
int f(int n...); // the comma has been omitted
It seems like this syntax is…

wefwefa3
- 3,872
- 2
- 29
- 51
42
votes
5 answers
Redundancy in OCaml type declaration (ml/mli)
I'm trying to understand a specific thing about ocaml modules and their compilation:
am I forced to redeclare types already declared in a .mli inside the specific .ml implementations?
Just to give an example:
(* foo.mli *)
type foobar = Bool of bool…

Jack
- 131,802
- 30
- 241
- 343
42
votes
4 answers
PHP: how to avoid redeclaring functions?
I tend to get errors such as:
Fatal error: Cannot redeclare get_raw_data_list() (previously declared in /var/www/codes/handlers/make_a_thread/get_raw_data_list.php:7) in /var/www/codes/handlers/make_a_thread/get_raw_data_list.php on line 19
how…

hhh
- 50,788
- 62
- 179
- 282