answersLogoWhite

0


Best Answer

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
This answer is:
User Avatar

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;

Related questions

Why should you declare variables?

Declaring of a variable in Java refers to creating a variable of a particular data type. Example: int x = 10; Here we are declaring an integer variable X and initializing it to a value of 10


In oops what is the difference between class variable and variable?

Class Variable is a subset of Variables.


Difference between declaring a variable and definition a variable?

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


How accessing a pointer an a variable differs?

Pointer-variables are variables, so there is no difference.


What is the difference between declaring static variable as local and global?

There are two ways to declare varibles. 1. Locally 2. Globally When you declare a variable locally in any function that means it is only accessible by that function. When you declare a variable globally so it is accessible by all the functions in the program. Declaring variables with static keyword means you are setting its value null.


WAP to show the difference between a variable and static variable?

difference between constant and static variables in java


What is constant variable in c?

Constant variables refers to those variables whose values cannot be changed. These variables should be initialized along with their declaration. Attempt to change the value of a constant variable will generate compile error. The syntax for declaring a constant variable is:const data-type variableName = value;


How are difference from independent variables?

Constants stays the same independent variables is the variable that is being manipulated


What is the difference between a manipulated and responding variable?

Manipulated variables are also known as independent variables. These are the variable which you change in an investigation. Plotted on the x axis.


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 object and variable?

A variable basically holds a single type literal in memory through defining its type, declaring it, and setting a value to it. If you meant reference variables, they are variables which refer to the memory location of an object previously set.An object is the actual storage space in memory in which some collection of data resides (is stored). Objects 'live' in memory spaces known as 'heaps'.