C Programming Questions and Answers – Type Conversions – 1

«
»
This section on C language interview questions and answers focuses on “Type Conversions”. One shall practice these interview questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C language interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C language interview questions on “Type Conversions” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         float x = 0.1;
  5.         if (x == 0.1)
  6.             printf("Sanfoundry");
  7.         else
  8.             printf("Advanced C Classes");
  9.     }

a) Advanced C Classes
b) Sanfoundry
c) Run time error
d) Compile time error
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

2. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         float x = 0.1;
  5.         printf("%d, ", x);
  6.         printf("%f", x);
  7.     }

a) 0.100000, junk value
b) Junk value, 0.100000
c) 0, 0.100000
d) 0, 0.999999
View Answer

Answer: b
Explanation: None.

3. What will be the output of the following C code? (Initial values: x= 7, y = 8)

advertisement
advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         float x;
  5.         int y;
  6.         printf("enter two numbers \n", x);
  7.         scanf("%f %f", &x, &y);
  8.         printf("%f, %d", x, y);
  9.     }

a) 7.000000, 7
b) Run time error
c) 7.000000, junk
d) Varies
View Answer

Answer: c
Explanation: None.

4. What will be the output of the following C code?

advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double x = 123828749.66;
  5.         int y = x;
  6.         printf("%d\n", y);
  7.         printf("%lf\n", y);
  8.     }

a) 0, 0.0
b) 123828749, 123828749.66
c) 12382874, 12382874.0
d) 123828749, 0.000000
View Answer

Answer: d
Explanation: None.

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 97;
  5.         char y = x;
  6.         printf("%c\n", y);
  7.     }

a) a
b) b
c) 97
d) Run time error
View Answer

Answer: a
Explanation: None.

6. When double is converted to float, then the value is?
a) Truncated
b) Rounded
c) Depends on the compiler
d) Depends on the standard
View Answer

Answer: c
Explanation: None.

7. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         unsigned int i = 23;
  5.         signed char c = -23;
  6.         if (i > c)
  7.             printf("Yes\n");
  8.         else if (i < c)
  9.             printf("No\n");
  10.     }

a) Yes
b) No
c) Depends on the compiler
d) Depends on the operating system
View Answer

Answer: b
Explanation: None.

8. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 23;
  5.         char c = -23;
  6.         if (i < c)
  7.             printf("Yes\n");
  8.         else
  9.             printf("No\n");
  10.     }

a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter