- #1
hafiz16
- 4
- 0
hi please tell me how variable declaration & initializing in C Language..whit examples..
hafiz16 said:hi please tell me how variable declaration & initializing in C Language..whit examples..
int variable;
int variable = 312;
If you're going to be doing any significant amount of C programming, I strongly recommend buyinghafiz16 said:i conslut many teachers & book..but this is not clear in my mind..
It could very well be a terminology thing. Back when I first learned this madness, the terms "declaration" and "initialization" were just glossed over and everybody called it variable assignment or ran the two together. Giving hafiz16 the benefit of the doubt, he was probably a bit muddled on how the two terms differ and what they do and confused his poor proffs while trying to get himself sorted out. I looked at what google returns and can see how some of it maybe confusing to a total newbie.Asking questions that are answered and explained in first chapter of every existing book on C programming means you have not even tried to find the answer on your own.
char string[20] = "This is a sting";
Borek said:Don't be a lazy bum. Asking questions that are answered and explained in first chapter of every existing book on C programming means you have not even tried to find the answer on your own.
struct whatEver {
int x, y, z;
float q;
}
/* declare a whatEver variable named test */
struct whatEver test;
/* same thing with pointers */
struct whatEver *pTest;
You can find it for cheaper, and it's a really good book. It actually explains all the concepts, and does it really clearly and concisely (excellent example of technical writing.) Take it out from the library and see if it's your speed, but that's totally not a reason to not but the book. I've read dozens of books on different languages, and this ones my fave; python made more sense to me after reading it 'cause it's really good on paradigms and all the other technical stuff.technoweasel said:By the way, don't bother with K&R. It seems really overpriced.
If you're using a pocket guide, you may as well use one of the APIs posted online (The C Library Reference Guide) or the api for your OS.O'Reilly pocket guide for C (it has a pink cow on the cover and is only like $10)
technoweasel said:Code:struct whatEver { int x, y, z; float q; } /* declare a whatEver variable named test */ struct whatEver test; /* same thing with pointers */ struct whatEver *pTest;
Variable declaration refers to the act of defining a variable by specifying its data type and name. On the other hand, initialization refers to assigning a value to that variable. In C language, a variable can be declared without being initialized, but it is good practice to initialize a variable at the time of declaration.
To declare a variable in C language, you need to specify the data type followed by the variable name. For example, int num;
will declare a variable named num
of type int
.
Initializing a variable means assigning a value to it at the time of declaration. This value can be a constant, an expression, or the value of another variable. For example, int num = 10;
will initialize the variable num
with a value of 10
.
Yes, a variable can be reinitialized in C language. This means that you can assign a new value to a variable that was previously declared and initialized. For example, num = 20;
will reinitialize the value of num
to 20
.
Variables are used to store and manipulate data in a program. Declaring a variable ensures that the compiler knows what type of data that variable will hold, and initializing it gives it an initial value to work with. This allows for more efficient and accurate coding in C language.