in Education by
Please help me in understanding the following C Output: #include int main() { float x = 4.0; printf("%f\n",x); printf("%d\n",x); int y=x; printf("%d\n",y); return 0; } Ouput on gcc compiler 4.000000 0 4 As far as i have read when we assign float to an int variable the decimal part of the variable is terminated and then assigned to the int. Why it is not happening in this case? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You're not printing y, you're printing x again. As a side note, printf can't do conversions. So passing a float when a %d is expected is undefined behavior.

Related questions

0 votes
    Please help me in understanding the following C Output: #include int main() { float x = 4.0; ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    Please help me in understanding the following C Output: #include int main() { float x = 4.0; ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    Please help me in understanding the following C Output: #include int main() { float x = 4.0; ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    Please help me in understanding the following C Output: #include int main() { float x = 4.0; ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Please help me in understanding the following C Output: #include int main() { float x = 4.0; ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Please help me in understanding the following C Output: #include int main() { float x = 4.0; ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Please help me in understanding the following C Output: #include int main() { float x = 4.0; ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    In scala, it is OK to convert a variable in the Seq, but if I construct the Seq with :: it ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    int fun(int n) { if(n!=0) { return n – fun(n-5); } else { return n; } } int main(){ int n = 20, z; z = fun(n); printf(“%d”, z); } Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    2; int i int n 92; while(i...
asked Dec 12, 2021 in Education by JackTerrance
0 votes
    Q.32 :-What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile? ... y); return 0; Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    What is the output of the below program? #include int main() { printf("%u",sizeof(NULL)); return 0; }...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
    How can someone parse a numeric string like "121.5555" to it's corresponding float value 121.5555? or parse a ... str to an int. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    If an expression contains double, int, float, long, then the whole expression will be promoted into which of ... questions and answers pdf, java interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
...