This C interview questions-Variables and Identifiers providing all the interview questions on variables including the definition of a variable need of variable, what is a local variable, global variable, scope and lifetime.
About C Interview Questions-Variables
What is data type?
Data type describes
1) How much memory allocated to a variable
2) What type of data is allowed to store in the variable?
Why data types required?
To represent data easily.
To identify the size of application
What is variable?
Named Memory allocation
Setting identities to named memory locations by which we can process the information easily.
What is Local variable?
Declaration of the variable inside the block or function is called local variable.
A local variable can be accessed only within the block in which it has defined.
What is Global variable?
Declaration of Global variable outside to all the blocks and functions.
Where to access global variable?
A global variable can be accessed anywhere in the application.
Rules of variable creation?
Cannot start with a digit but can have digits.
only ‘_’ is allowed and declaration and can start with ‘_’
Cannot match with keywords.
How to differentiate Constant variables and variables?
Constant variables mostly defined using upper case characters. Hence we can easily identity constant variables from other variables.
What is the Default value of int local variable?
In the declaration of the local variable, if we do not provide any value, it is initialized with Garbage value.
What is Garbage value?
Random integer value either positive or negative.
What are default values of global variables of different data types ?
int -> 0
float -> 0.000000
char -> blank(‘\0’)
pointer -> NULL
Can we define global variable and local variable with the same name?
Can we access global variable if local variable present inside a function?
No, first priority to a local variable while accessing from the function.