answersLogoWhite

0

In C, C++ and Java, all variables must be declared before they can be used. A declaration determine's the variable's type and name, nothing more. The type must be visible to the compiler at the point of declaration in order to determine the amount of memory require by that type. The type naturally determines what type of data may be stored in the variable. The name is user-defined and must be unique to the scope in which the variable is declared. The name provides a reference to the memory address allocated to the variable at runtime.

In C, variables are always uninitialised (they have no value). As such, C programmers typically declare all variables used by a function at the top of the function, initialising them as and when required. This can lead to problems if the programmer forgets to initialise the variable before using it, however the compiler should emit a warning to guard against this. If the programmer ignores the warning, the program will have undefined behaviour.

C++ and Java are similar to C in that respect but, unlike C, variables may be initialised at the point of declaration (assigned a value of the type). This encourages programmers to declare variables at the point they are actually required rather than up front.

Constants are similar to variables except they do not change value once initialised. Constants must always be initialised at the point of declaration except in C++ when declaring a constant at class scope; it must be initialised at global scope (outside the class). In Java, constants are declared with the 'final' keyword before the variable's type. Both C and C++ use the 'const' keyword.

Variables may also be declared volatile which means the variable's value is outwith the control of the process or thread in which it is declared and could change at any time. Declaring a volatile simply ensures that the variable cannot be read during a write (creating a race condition) and that all access must occur in main memory; the variable cannot be cached.

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

Why do you use single quotation for declaring a single character in java programs?

This was simply the choice of the language designers, who probably decided to carry over that convention from the C/C++ languages.


The PHP syntax is similar to which languages?

Its similar to a number of languages such as C, C++, Java and Perl.


What are the features in java that makes it similar to C programming?

Java is not similar to C. Java is, however, similar to C++. Both C++ and Java are object orientated programming languages (OOPL's).


How are viruses being programmed?

They are programmed in programming languages or scripting languages like Visual basic , c , c++,java , vb script or java script.


C plus plus and java are examples of what languages?

They are not examples of languages. They arelanguages.


What is feature that supported in c c plus plus and java but not in net?

C, C++ and Java are cross-platform languages. NET is for Windows-only.


How is java different than any other OOP languages like C plus plus?

Every languages are different, a C++ compiler cannot compile a Java source.


What is syntax in c plus plus for declaring a variable?

type variable {[optional array size]} {= optional initializer};


What in computing is java python and c?

They are all programming languages.


How virus are being programmed?

They are programmed in programming languages or scripting languages like Visual basic , c , c++,java , vb script or java script.


How many programming languages are based on C?

C++, Java, Perl, Python, PHP, JavaScript, LPC, C# is the most popular languages based on C, but there is probably more languages.


What languages are used to design Android OS?

It is a Linux-based open source operating system. Programming languages are in C, C++, and Java, with apps being written in a customized version of Java.