- Home
- Interview Questions
- C Programming
Because each member in a union is stored in the same memory location, the amount of room required to store the union is equal to that of its largest member.
The data items in an array must all be of the same type. A structure can contain data items of different types.
The structure member operator is a period. It is used to access members of a structure.
A structure tag is tied to a template of a structure and is not an actual variable. A structure instance is an allocated structure that can hold data.
As your programs get bigger they will contain more and more variables. Global variables take up memory as long as the program is running, whereas automatic local variables take up memory only while the function they are defined in is executing. Hence, use of local variables reduces memory usage. More important, however, is that the use of local variables greatly decreases the chance of unwanted interactions between different parts of the program, hence lessening program bugs and following the principles of structured programming.
Yes. When you declare a local variable with the same name as a global variable, it is a completely different variable. This means that you can make it whatever type you want. You should be careful, however, when declaring global and local variables that have the same name. Some programmers prefix all global variable names with 'g" (for example, gCount instead of Count). This makes it clear in the source code which variables are global and which are local.
The scope of a variable refers to the extent to which different parts of a program have access to the variable, or where the variable is visible.
A variable with local storage class is visible only in the function where it is defined. A variable with external storage class is visible throughout the program.
Defining a variable in a function makes it local; defining a variable outside of any function makes it external.
Automatic (the default) or static. An automatic variable is created each time the function is called and is destroyed when the function ends. A static local variable persists and retains its value between calls to the function.