Type Casting & Integer Promotion

This C quiz covers explicit casts and the implicit conversions C performs on its own, like integer promotion and the usual arithmetic conversions. You will predict results where the type of an expression changes the answer and spot the classic signed/unsigned trap.

Médio 10 perguntas ~6 minutos Aprovação com 80% C17

Escolha um modo

Jogando como visitante: entre para guardar seu XP e sua sequência.

Pergunta de exemplo

Pergunta 1 de 10

What does this print?

#include <stdio.h>

int main(void) {
    int a = 7, b = 2;
    double r = (double)a / b;
    printf("%.1f\n", r);
    return 0;
}
Mostrar a resposta

A. 3.5 The cast applies to a before the division, so it is double / int, and b is converted to double too. The division keeps the fraction: 3.5.

O que este quiz cobre

  • Casting int to double before or after a division
  • Truncation when converting floating point to int
  • Integer promotion of char and short in expressions
  • Comparing signed and unsigned values
  • Overflow before widening

Perguntas frequentes

Preciso de uma conta?

Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.

Posso refazer?

Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.