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

I have done all of my readings, and searched the library as well as online. I cannot find the correlation that will explain this. Please help.

2007-06-19 10:01:02 · 4 answers · asked by Sean J 3 in Computers & Internet Programming & Design

4 answers

C is a typesafe language. Which means that the C compiler needs to know what type each variable is before it can use it. Declaration of a variable lets the compiler know what type (character, integer) the variable is so that it can use the variable for instance it can allocate space in memory accordingly.

By knowing the type of the variable the compiler can perform faster than if it had to each time interpret from the value the type of the variable.

2007-06-19 10:08:03 · answer #1 · answered by wooster 2 · 1 0

If you do not declare the variable before using it, the program will not set aside the necessary memory space for it to be used. Most older programming languages are like this. Newer languages allow for dynamic memory allocation which means that declaring the variables isn't necessary, it will just create the memory space as it is needed.

2007-06-19 17:05:36 · answer #2 · answered by truextremeicon 3 · 1 0

C itself is a typesafe static language, so it is necessary to declare variables, but the answer to your question is best answered by Visual Basic non-.net version, it has an "option strict" directive and often used as strict forces declaration.

If you done JavaScript, Perl, PHP or other dynamic and forgiving language you will find it out in a hard way.

2007-06-19 17:44:41 · answer #3 · answered by Andy T 7 · 1 0

The compiler needs to know what size and kind of memory space to reserve for that variable. Not enough memory and you get corrupted data and too much memory and you are wasting computer resources.

2007-06-19 17:06:22 · answer #4 · answered by Alan D 2 · 1 0

fedest.com, questions and answers