Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Type Conversions

C Programming Questions and Answers – Type Conversions

 

1.What is the output of this C code?

#include <stdio.h>

void main()

{

float x = 0.1;

if (x == 0.1)

printf(“studyhelpzone”);

else

printf(“Advanced C Classes”);

}

a) Advanced C Classes

b) studyhelpzone

c) Run time error

d) Compile time error

View Answer

Answer:a   

 

2.Comment on the output of this C code?

#include <stdio.h>

void main()

{

float x = 0.1;

printf(“%d, “, x);

printf(“%f”, x);

}

a) 0.100000, junk value

b) Junk value, 0.100000

c) 0, 0.100000

d) 0, 0.999999

View Answer

Answer:b 

3.What is the output of this C code?

(7 and 8 are entered)

#include <stdio.h>

void main()

{

float x;

int y;

printf(“enter two numbers \n”, x);

scanf(“%f %f”, &x, &y);

printf(“%f, %d”, x, y);

}

a) 7.000000, 7

b) Run time error

c) 7.000000, junk

d) Varies

View Answer

Answer:c 

4.What is the output of this C code?

#include <stdio.h>

void main()

{

double x = 123828749.66;

int y = x;

printf(“%d\n”, y);

printf(“%lf\n”, y);

}

a) 0, 0.0

b) 123828749, 123828749.66

c) 12382874, 12382874.0

d) 123828749, 0.000000

View Answer

Answer:d 

 

5.What is the output of this C code?

#include <stdio.h>

void main()

{

int x = 97;

char y = x;

printf(“%c\n”, y);

}

a) a

b) b

c) 97

d) Run time error

View Answer

Answer:a 

 

6.When double is converted to float, the value is?

a) Truncated

b) Rounded

c) Depends on the compiler

d) Depends on the standard

View Answer

Answer:c

 

7.What is the output of this C code?

 

#include <stdio.h>

int main()

{

unsigned int i = 23;

signed char c = -23;

if (i > c)

printf(“Yes\n”);

else if (i < c)

printf(“No\n”);

}

a) Yes

b) No

c) Depends on the compiler

d) Depends on the operating system

View Answer

Answer:b 

8.What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 23;

char c = -23;

if (i < c)

printf(“Yes\n”);

else

printf(“No\n”);

}

a) Yes

b) No

c) Depends on the compiler

d) Depends on the standard

View Answer

Answer:b 

 

 

 

9.function to lower(c) defined in library works for

a) Ascii character set

b) Unicode character set

c) Ascii and utf-8 but not EBSIDIC character set

d) Any character set

View Answer

Answer:d 

 

10.What is the output of the below code considering size of short int is 2, char is 1 and int is 4 bytes?

#include <stdio.h>

int main()

{

short int i = 20;

char c = 97;

printf(“%d, %d, %d\n”, sizeof(i), sizeof(c), sizeof(c + i));

return 0;

}

a) 2, 1, 2

b) 2, 1, 1

c) 2, 1, 4

d) 2, 2, 8

View Answer

Answer:c  

 

11.Which type conversion is NOT accepted?

a) From char to int

b) From float to char pointer

c) From negative int to char

d) From double to char

View Answer

Answer:b

Explanation:Conversion of a float to pointer type is not allowed.

 

12.What will be the data type of the result of the following operation?

(float)a * (int)b / (long)c * (double)d

a) int

b) long

c) float

d) double

View Answer

Answer:d 

 

13.Which of the following type-casting have chances for wrap around?

a) From int to float

b) From int to char

c) From char to short

d) From char to int

View Answer

Answer:b  

 

14.Which of the following typecasting is accepted by C?

a) Widening conversions

b) Narrowing conversions

c) Both

d) None of the mentioned

View Answer

Answer:c

 

15.When do you need to use type-conversions?

a) The value to be stored is beyond the max limit

b) The value to be stored is in a form not supported by that data type

c) To reduce the memory in use, relevant to the value

d) All of the mentioned

View Answer

Answer: d   

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button