+ 1

what is the declare, define and initialize terms mean?

for function, variables and object

22nd Jun 2016, 9:24 AM
VISHAL PRAJAPATI
VISHAL PRAJAPATI - avatar
10 Antworten
+ 3
declare = make a space in memory for variable, by declaring a type we say how much is that space (integer bigger that char for example) define = declare + choose a name for that variable initialize = give a value to declared variable *Edit noted by @Kumar: Initialisation - FIRST time giving a value (I can agree on that). PS: It seems that sometimes professionals are using both declare and define as the same thing too...
22nd Jun 2016, 10:58 AM
Nikola Dedović
+ 1
This is only true for variables. For functions, a declaration merely tells the compiler that there might be a function *defined* with this signature. This is useful if the definition (i.e. the actual coding) of the function is somewhere else - either in the code or binary. The declaration of a function tells the compiler that this name is defined, what parameters the function expects and what it returns. Thus the compiler can can generate all the code required to call the function without the need to know its definition. The definition is then only required in the the linking step. We are actually using it all the time in headers, if we do not define functions in headers that is. (There's no initialize for functions.)
22nd Jun 2016, 3:13 PM
Stefan
Stefan - avatar
+ 1
both the answers are wrong.... define means to create something ( varuable, function , class.etc) or to give definition to something. declare means to make an instance of already defined stuff (function, variable etc) to increase the scope in which they can be used initialize means to give the stuff you defined its first value...like int i=10; variable i defined with 10 initialized to it
25th Jun 2016, 2:39 PM
Mukul Kumar
Mukul Kumar - avatar
26th Jun 2016, 5:20 AM
Mukul Kumar
Mukul Kumar - avatar
0
@Kumar, you said "declare to make an instance", yees but you can declare and a variable of a primitive type which doesn't have its class so there isn't an "instance" of a primitive type and still it is declared... essentialy declare means what I've mentioned and scopes are an entire a different story, side effects... You're in right in 3th definition when you said that "Initialisation = FIRST time giving a value"
25th Jun 2016, 6:08 PM
Nikola Dedović
0
@Stefan, good catch, upvote.
25th Jun 2016, 6:35 PM
Nikola Dedović
0
@dedovic....my answer is right and you may check it here http://stackoverflow.com/questions/23345554/the-differences-between-initialize-define-declare-a-variable also .... have you ever wondered why do we have to write function names above main ()? well... to declare what is defined after main ()....means technically increasing the function's scope.....
26th Jun 2016, 2:48 AM
Mukul Kumar
Mukul Kumar - avatar
0
@Kumar, I'm not entering into ins and outs of f-tions, scopes and declarations "before" or after the main, I'm just repeating a very simple fact which I've beforementioned about declaring a (implicitly, what begginers are interested the most in) variable... Yea, I've read that first time, probably my d-tion, weren't complete enough and were simplified...
26th Jun 2016, 5:14 AM
Nikola Dedović
0
@Kumar, probably a f-tion's prototyping is what we can additionaly consider under some kind of declaring but I weren't 100% sure that when somebody asking for the most general definiton of declaring, he implicits and about f-tion's prototyping...
26th Jun 2016, 5:27 AM
Nikola Dedović
0
""Definition" refers to the place where the variable is created or assigned storage; "declaration" refers to places where the nature of the variable is stated but no storage is allocated." From "C programming language" K&R 2nd ed...
7th Jul 2016, 2:23 PM
Nikola Dedović