C Data Type Interview Questions and Answers: Sizes, Conversions, and Traps

Prepare for C interviews by learning what the standard guarantees and what depends on the implementation. Follow a complete integer-promotion trace, then review type selection and common output traps.

KnowledgeGate Team

Exam prep & CS education

Updated 1 Dec 20266 min read
C Data Type Interview Questions and Answers: Sizes, Conversions, and Traps

Memorising char = 1 byte and int = 4 bytes is not enough for a C interview. A strong answer separates what the C language guarantees from what a particular compiler and machine choose. The aim is not to recite a size table. It is to track the type and value of every expression, especially when promotions and conversions occur. These model answers explain the reason behind each rule and build towards one complete conversion trace you can reproduce at the interview table.

What a C data type controls beyond byte size

A data type is a contract. It determines the set of values an object can hold, the operations permitted on those values, representation constraints, and how values participate in conversions.

C's fundamental types include:

  • _Bool for truth values

  • character types: char, signed char, and unsigned char

  • signed and unsigned integer types

  • floating types: float, double, and long double

  • void, which represents the absence of a value or complete object type

Pointers, arrays, structures, and unions are constructed from these building blocks; their object and memory rules add another layer beyond fundamental types.

Model interview answer: A data type in C defines the values an object can represent and the operations and conversions that apply to it. Its size matters, but so do range, signedness, representation, and expression rules.

const and volatile are type qualifiers. They modify how a type may be used, but they do not replace the need to understand the underlying type. The earlier Intro & Data Types Interview Questions and Answers post owns C introduction, declarations, literals and default-value questions. The deeper interview layer is implementation-defined sizes, promotions, conversions, floating-point behaviour, type selection and output traps.

How to answer size, range, and signedness questions correctly

Do not begin with “int is 4 bytes”. C does not guarantee that. Begin with the portable facts: sizeof(char) == 1, one C byte contains CHAR_BIT bits, and the implementation chooses the exact widths and ranges of most fundamental types. Inspect them with sizeof, <limits.h>, and, when an exact-width interface matters, <stdint.h>.

Plain char, signed char, and unsigned char are three distinct types. The implementation decides whether plain char has the same range and behaviour as signed or unsigned char.

Rapid model answers:

  • Is int always 4 bytes? No. Check the implementation.

  • Is char always signed? No. Plain char signedness is implementation-defined.

  • What is sizeof('A') in C? It is sizeof(int), because an ordinary character constant such as 'A' has type int. The result is not guaranteed to be 4.

Use this inspection pattern:

c
printf("%zu\n", sizeof(int));

The result of sizeof has type size_t, and %zu is the matching printf conversion. The C Language course provides a deeper route through these rules and their practice questions.

Fully worked example: integer promotion first, narrowing later

Integer promotion makes 250 plus 10 equal 260, then narrowing stores 4 in unsigned char.

Assume CHAR_BIT = 8, UCHAR_MAX = 255, sizeof(int) = 4, and that int can represent 260. Now trace this code without skipping the expression types:

c
unsigned char u = 250;
int delta = 10;
int total = u + delta;
unsigned char stored = u + delta;
printf("%d %u\n", total, (unsigned)stored);
  1. u starts as an unsigned char with value 250. Because int can represent every value from 0 through 255 in this environment, integer promotion converts u to int with value 250.

  2. delta is already an int with value 10. The addition is therefore int 250 + int 10, which produces the int value 260.

  3. total receives that value unchanged, so total is 260.

  4. The second addition also produces int value 260. Assigning it to the 8-bit unsigned char stored converts it modulo UCHAR_MAX + 1. Therefore, 260 mod 256 = 4.

The exact output under the stated assumptions is:

Code
260 4

Interview follow-up: Did unsigned overflow occur during u + delta? No. The addition happened in int. The modulo conversion occurred later, when 260 was stored in unsigned char.

Integer promotion and narrowing convert 250 plus 10 to 260, then store 4 in unsigned char.

Floating-point questions: literals, division, and precision

float, double, and long double are distinct real floating types. double provides at least as much precision as float, and long double provides at least as much as double, but their exact sizes and representations are implementation-specific.

Literal suffixes determine type: 3.14 is double, 3.14f is float, and 3.14L is long double.

For division, operand types control the operator:

  • 5 / 2 performs integer division and produces 2.

  • 5 / 2.0 converts the left operand to double and produces 2.5.

Even double result = 5 / 2; stores 2.0, because the integer division finished before assignment.

Binary floating-point values should often be compared with a tolerance:

c
double actual = 0.1 + 0.2;
double expected = 0.3;
if (fabs(actual - expected) < 1e-12) {
    /* close enough for this example */
}

Here 1e-12 suits this small illustration. It is not a universal tolerance. Choose one according to the problem's magnitude and error model.

Type-selection questions that reveal engineering judgement

Good type selection communicates the domain and matches the surrounding interface.

Scenario

Suitable type

Reason

Buffer length payload_bytes = 4096

size_t

It is the type returned by sizeof and used by allocation APIs.

Protocol field holding exactly 32 unsigned bits and 4,000,000,000

uint32_t

Use it when the implementation provides that exact-width type. Initialise with UINT32_C(4000000000) and print with the matching <inttypes.h> macro, such as PRIu32.

Pointer difference of -12 elements

ptrdiff_t

It represents signed differences between pointers into the same array.

True or false state is_ready = 1

_Bool

It expresses a logical state without inventing an unrelated numeric domain.

Model interview answer: Do not use int everywhere. Choose a type that communicates the value's domain, covers its required range, matches library interfaces, and preserves an external format when exact width is part of the contract.

Fixed-width types are valuable for exact-width protocols and file formats. They are not an automatic replacement for every loop counter or ordinary integer.

Four data-type traps interviewers use in output questions

Consider this comparison:

c
int i = -1;
unsigned int n = 1U;
printf("%d\n", i < n);

The output is 0. The usual arithmetic conversions change i to unsigned int. Converting -1 produces UINT_MAX, which is not less than 1U.

Do not confuse this defined conversion with signed overflow. Signed integer overflow has undefined behaviour. Unsigned arithmetic is defined modulo one more than the type's maximum value.

Snippet

Correct result or status

Why

i < n above

0

-1 converts to UINT_MAX before comparison.

sizeof(void)

Not valid standard C

void is an incomplete type and has no object size.

void_ptr + 1

Not valid standard C

Standard pointer arithmetic needs a pointed-to object type with a defined size.

printf("%u\n", -1)

Undefined behaviour

%u expects unsigned int, but the argument has type int.

Is plain char signed?

Implementation-defined

A compiler may give plain char a signed or unsigned range.

Some compilers accept sizeof(void) or arithmetic on void * as extensions. That does not make those expressions portable C. Test these distinctions with about 40 Data Type Fundamentals MCQs and Solved Questions.

The short version for service and product interviews

Interview patterns vary. Screening rounds often begin with definitions, sizes, format specifiers, and short output snippets. Deeper technical rounds are more likely to probe portability, conversions, undefined behaviour, and why a type fits an API or data contract.

Use this four-step answer template:

  1. State the C language rule.

  2. Name any implementation assumption.

  3. Trace each operand's type and value.

  4. Finish with the portability or engineering implication.

For the worked example, that becomes: u promotes to int, 250 + 10 produces int value 260, and only the later assignment converts 260 modulo 256 to 4.

Never assume fixed widths, track promotions before arithmetic, distinguish signed and unsigned rules, and match every type with its format specifier. Continue with Coding for Placement for structured practice, then use the Resume and Interview preparation section for broader interview guidance.