What's the difference between definition and declaration in C++? | Sololearn: Learn to code for FREE!

+1

What's the difference between definition and declaration in C++?

And can I call parameter a variable?? What's the difference between reference and variable?

4/25/2021 4:40:37 PM

Mohammad Mehedi Hasan

9 Answers

New Answer

+3

Declaration of a variable is for informing to the compiler the following information: name of the variable, type of value it holds and the initial value if any it takes. i.e., declaration gives details about the properties of a variable. Whereas, Definition of a variable says where the variable gets stored. no, you can't call a parameter as variable. Variables are kinda label for the memory that stores the actual data. Pointers stored the address of the variables. References are alias for the variables.

+3

For a variable X: // declararion int x; // definition x = 20; // declaration & definition int x = 20; All variables must be declared before defining them and whenever you define a variable, you're simply assigning a value to them. Also a parameter is a variable, whenever you call a function with a parameter, a copy of such parameters are implicitly created except if the parameters are passed by reference. void foo(int x) // a copy of x is created void foo(int &x) // referenced reference is a pointer to a variable. So a reference POINT AT a variable

+1

...the title and description aren't matching. do you wanna ask about all four or any two?

+1

Coding Kitty Does function hold space in memory too?

+1

they do. even if you don't call them in the main function. but you shouldn't be concerned about that for now.

+1

codingKitty might have his/her reason for saying that but to me, a parameter is a local variable that also have their separate address in memory. Whenever you call a function &parameter = copy of the argument Except if the parameter's declaration was preceded by the reference operator

0

Coding Kitty I am sorry for this All four..

0

Mirielle Ok, variable declaration and defination - ✅ But are you calling parameter a variable?? Coding Kitty said, parameters and variables aren't same...:/ I don't get it..

0

Mirielle https://code.sololearn.com/cq1S7wD2B9vx/?ref=app Here parameter has an adress too.. 🤔 Whatever, I ran the program 10-12 times and it's changes memory location.. Can you please search for where did I go wrong??