Interview Questions
Declarations and Initializations · Study material
Declarations and Initializations – Interview Questions
1. What is the difference between a declaration and a definition?
A declaration introduces a name and its type; a definition also allocates the object or provides the function body. extern int x; declares; int x = 3; defines.
2. Is there a difference between extern int fun(); and int fun();?
No. Function declarations have external linkage by default, so extern adds nothing.
3. What type does a real constant like 3.14 have?
double. Write 3.14f for float and 3.14L for long double.
4. What are the types of linkage in C?
External (visible across files), internal (static at file scope, one file) and none (local variables and parameters).
5. Which special character can appear in a C identifier?
Only the underscore. Identifiers use letters, digits and _, and cannot start with a digit.
6. When is a function prototype needed?
Before the first call, so the compiler knows the parameter and return types. Since C99, calling an undeclared function is an error.
7. What value does an uninitialised variable have?
Locals: indeterminate. Globals and statics: zero.
8. What happens with int a[5] = {1, 2};?
a[0] = 1, a[1] = 2, and the remaining three elements are 0.
9. What is a designated initializer?
An initializer that names its target: int a[10] = {[9] = 1}; or struct point p = {.y = 2};. Unnamed elements are zero.
10. What does volatile mean?
The object can change in ways the compiler cannot see, so every access must be performed exactly as written. Used for memory-mapped hardware and flags set by signal handlers.
11. What is a tentative definition?
A file-scope declaration without an initializer or extern, such as int count;. It may be repeated, and becomes a zero-initialised definition if no real definition follows.
12. Which declarations did C23 add?
constexpr objects, auto type inference, typeof, the empty initializer = {} and the nullptr constant.