+ 2
What is the difference between definition and declaration??
in c or c++
7 Respostas
+ 7
int x; You are declaring the variable
x = 5; You are defining it's value
int x = 5; You are declaring the variable and assigning it a value.
+ 6
int x; // declaration
int y = 5; // definition
I think that declaration is declaring a variable (x is of type int)
And that definition is defining a variable (x is 5)
+ 5
@Mrinal No! It allocates memory when you create a variable (declare it as something). So when you do int x; it allocates memory for an integer named x. This is why you can use pointers when a variable doesn't have a value assigned. Technically, though, it does have a value when declared. When you define it you are just changing its value. It has a default value of null. So:
int x;
int* ptr = &x;
cout <<ptr<<endl <<x;
There has to be something there for the pointer to point to.
+ 1
Have you had a look at abstract classes? Then you'll know.
+ 1
I want to say in declaration doesn't occupy any memory.... the moment we define it by assigning a value to it , occupies memory...
am I r8????? @J.G
+ 1
J.G I will suggest u Google about difference between declaration and definition... u can find there the concept of allocation of memory..
only by definition memory is allocated...😎😎😎😎😎
0
yahh it's ok from Syntex but what is the difference between
int x;
x = 5;
and
int x=5;
@j.g