answersLogoWhite

0

Actually, there is a third step, call definition.

Declaration is a statement to the compiler of what type an identifier is, definition is the allocation of memory for that identifier, and initialization is the assignment of an initial value to that identifier. Usually, declaration and definition are done together, but you can also add initialization in that step if desired.

int a; /* declaration and definition */

a = 1; /* initialization */

int a = 1; /* declaration, definition, and initialization */

For the case of seperate declaration and definition, consider the struct...

struct _mystruct { int a; }; /*declaration */

struct _mystruct mystruct; /* definition */

struct _mystruct { int a; } mystruct; /*declaration and definition */

Note: To be more precise:

struct _mystruct; /* struct declaration */

struct _mystruct { int a; }; /* struct definition */

typedef struct _mystruct MYTYPE; /* type definition */

extern struct _mystruct mystructvar; /* variable declaration */

struct _mystruct mystructvar; /* variable definition */

struct _mystruct mystructvar = {7} ; /* variable definition with initialization */

struct _mystruct { int a; } mystruct; /* struct definition and variable definition */

extern struct _mystruct { int a; } mystruct; /* struct definition and variable declaration */

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
ReneRene
Change my mind. I dare you.
Chat with Rene

Add your answer:

Earn +20 pts
Q: What is the difference between declaring variable and initializing variables?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Math & Arithmetic

Difference between declaring a variable and definition a variable?

Declaration is a promise: 'I will define (or has defined) this variable/function somewhere else'.


What is the difference between variables and rules?

a variable changes a rule doesnt.


The difference between the independent and dependent variables?

Independent variables are variables that can be changed in an experiment, while dependent variables are variables that change as a result of an experiment. In other words, independent variables are what you change, and dependent variables are the results of the experiment.


What is the difference between dependent and controlled variables?

The controlled variable is the one that you chose to change while the dependant is the variable that changes because it is effected by the controlled variable


What is difference between an instance variable and a class variable?

An instance variable is typically associated with an object instance of the class whereas class variable is not associated with any object instance. Static variables are referred to as class variables while non-static regular variables are called instance variables. Simply put, you will have as many instances of the instance variable as there are object instances. i.e., if there are 10 instances of an object, you will have 10 instances of that instance variable as well. But, there will be only one instance of the static or class variable. Instance variables are accessed as follows: objname.variableName; Class variables are accessed as follows: ClassName.variableName;