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.

Mittel 10 Fragen ~6 Minuten Bestanden ab 80% C17

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 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;
}
Lösung zeigen

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.

Darum geht es in diesem Quiz

  • 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

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.