English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

give me with an example...

2007-09-27 20:58:09 · 6 answers · asked by Anonymous in Computers & Internet Programming & Design

6 answers

If you know C, you will know the answer. If you don't know C, you don't need to know the answer.
If you don't know C, but need to know the answer, you need to find better ways to get your homework done, or perhaps consider dropping out of a class for which you are not suited.

2007-09-27 21:10:22 · answer #1 · answered by oracle128au 7 · 0 1

All of the answers above are incorrect, presumably because the answerers are familiar with C++, where the distinction is more blurred. In C, an initializer declared outside of a function, or inside a function with the 'static' keyword, does not generate any code. Instead the variable is loaded when the program is loaded. The expression on the right must be a constant expression. Examples are:

int x = 3; /* a variable declaration and initializer */
static int y = 3; /* a static variable declaration and initializer */
int y = x+1; /* this is illegal -- expression is not constant */

myfunc()
{
  static int z = 3; /* a static variable declaration and initializer */
}

A non-static initializer or assignment statement inside of a function are basically identical: the expression on the right is evaluated and stored in the variable when the line of code is executed at run time (not load time). Examples are:

myfunc()
{
  int z = 3; /* a non-static variable declaration and initializer but really an assignment */
  int w; /* a variable declaration */

  w = 4; /* an assignment statement */
}

See the link for more information.

2007-09-29 15:58:19 · answer #2 · answered by noworryz 5 · 0 1

If you are using

int counter=1;

This is known as intialisation, generally when you give an intail value to a variable at the time of declaration then this is know as intialisation.

But if you are using following code

int a,b; //no initial value is given to them and bot ha.b have garbage values

b=10; //10 is assigned to be
a=b; // b is assigned to a

If variable is not given any initial value it contains a Garbage Value.

In certain situations intialisation is necessary
eg:

for(i=1;i<=5;i++)
{


}

2007-09-28 04:33:05 · answer #3 · answered by Shariq (http://coinsindia.info) 5 · 0 1

Essentially there is no difference between initialization and assignment. They both allocate a value to a variable.

Initialization is usually at the time of allocating the variable.
float sum=0.0;

Assignment can occur at any time within the program
sum=sum+data;
or
b=a;

I hope this helps.

2007-09-28 04:11:05 · answer #4 · answered by AnalProgrammer 7 · 0 1

int a=2;//initialization
a=5;//assignment

2007-09-28 05:39:19 · answer #5 · answered by i_am_the_next_best_one 5 · 0 1

there is no need to answer this "lazy" question..

this should not have been posted in the first place..

if we get spam mails, this is the "spam" question... :p

2007-09-28 04:38:00 · answer #6 · answered by Christopher 2 · 1 1

fedest.com, questions and answers