C variables have an explicit type declared before the name: int count = 0;. Unlike JavaScript, you cannot silently change a variable from int to char * without a compile error.
Common scalar types
int,long— integers (width is platform-defined; use<stdint.h>for fixed sizes)double,float— floating point (preferdoublefor precision)char— single byte character; also used in strings_Boolorboolwithstdbool.h— true/false
Declaration and initialization
int age = 30;
double pi = 3.14159;
char letter = 'A';
Uninitialized local variables contain indeterminate values—always initialize before use.
Important interview questions and answers
- Q: Size of int?
A: At least 16 bits per standard; typically 32 bits on modern desktops—useint32_twhen width matters. - Q: char signed or unsigned?
A: Implementation-defined; usesigned charorunsigned charexplicitly when it matters.
Self-check
- Why initialize local variables?
- Which header provides fixed-width integers like int32_t?
Interview prep
- Why initialize locals?
Reading uninitialized automatic variables is undefined behavior—the value is indeterminate.
- When use stdint.h?
When exact bit widths matter—embedded systems, network protocols, and cross-platform binary formats.