What should be the output: int main(){ int a = 10.5; printf("%d",a); return 0;} *
2 points
(A) 10.5
(B) 10
(C) 0
(D) Compilation Error
Answers
10 will be the output.
(B) 10
Let's correct the question
What should be the output:
int main() {
int a = 10.5;
printf("%d",a);
return 0;
}
(A) 10.5
(B) 10
(C) 0
(D) Compilation Error
Explanation
The variable 'a' is given data type as int but, the value stored in the variable 'a' is in decimal or you can it's a float value.
So, when the compiler compiles the program the variable stores only the integer part i.e. 10, or can be said as converts the float value to an integer value and it prints out 10 as output.
%d is used for integer type values and %f is used for float type values (real numbers)
The cỏde is written in C language.
C programming language was designed by Dennis Ritchie and it is a procedural programming language.
What should be the output: int main(){ int a = 10.5; printf("%d",a); return 0;}
(A) 10.5
(B) 10
(C) 0
(D) Compilation Error
#MagnificentSquad
#CarryOnLearning
#BrainlyFast