LearnFrenzy
Sign in Take a free test

Declarations and Initializations · Predict the Output · Question 6

Conversions during initialisation – output Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

What is the output of the following C program on a 64-bit system?

main.c
#include <stdio.h>

int main(void) {
    int i = 7.9;
    double d = 7 / 2;
    char c = 65 + 1;
    printf("%d %.1f %c\n", i, d, c);
    return 0;
}
  • A 7 3.0 B Correct
  • B 8 3.5 B
  • C 7 3.5 A
  • D 7 3.0 A
Correct Answer: Option A

The initializer is converted to the variable's type: 7.9 truncates to 7; 7 / 2 is integer division (3) before becoming 3.0; 66 is the code of 'B'.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links