Question On Datatypes.docx

  • Uploaded by: vishal kumar
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Question On Datatypes.docx as PDF for free.

More details

  • Words: 1,086
  • Pages: 9
Question 1 Suppose a C program has floating constant 1.414, what's the best way to convert this as "float" data type? A

(float)1.414

B

float(1.414)

C

1.414f or 1.414F

D

1.414 itself of "float" data type i.e. nothing else required.

The correct answer is C. Question 2

What will be output when you will execute following c code? #include<stdio.h> int main(){ volatile int a=11; printf("%d",a); return 0; } Choose all that apply: 11 (B) Garbage (C) -2 (D) We cannot predict (E) Compilation error (A)

The correct answer is D. Question 3 “typedef” in C basically works as an alias. Which of the following is correct for “typedef”? A

typedef can be used to alias compound data types such as struct and union.

B

typedef can be used to alias both compound data types and pointer to these compound types.

C

typedef can be used to alias a function pointer.

D

typedef can be used to alias an array.

E

All of the above.

The correct answer is E.

Question4 In a C program snippet, followings are used for definition of Integer variables? signed s; unsigned u; long l; long long ll; Run on IDE Pick the best statement for these. A All of the above variable definitions are incorrect because basic data type int is missing. B All of the above variable definitions are correct because int is implicitly assumed in all of these. C Only “long l;” and “long long ll;” are valid definitions of variables. D Only “unsigned u;” is valid definition of variable. The correct answer is B.

Question5 Predict the output of following program. Assume that the numbers are stored in 2's complement form. #include<stdio.h> int main() { unsigned int x = -1; int y = ~0; if (x == y) printf("same"); else printf("not same"); return 0; }

A

Same

not same B The correct answer is A.

Question 6 Which of the following is not a valid declaration in C? 1. short int x; Run on IDE 2. signed short x; Run on IDE 3. short x; Run on IDE 4. unsigned short x; THE OPTIONS ARE: A

3 and 4

B

2

C

1

D

All are valid

The correct answer is D. Question 7 Predict the output #include <stdio.h>

int main() { float c = 5.0; printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32); return 0; } THE OPTIONS ARE: A

Temperature in Fahrenheit is 41.00

B

Temperature in Fahrenheit is 37.00

C

Temperature in Fahrenheit is 0.00 Compiler Error

D The correct answer is B

Question 8 Predict the output of following C program #include <stdio.h> int main() { char a = '12';

printf("%d", a);

return 0; } Run on IDE A

Compiler Error

B

12

C

10

D

Empty

The correct answer is C. Question 9 In C, sizes of an integer and a pointer must be same. A

True

B

False

The correct answer is false Question 10 Output?

int main() { void *vptr, v; v = 0; vptr = &v; printf("%v", *vptr); getchar(); return 0; } Run on IDE A

0

B

Compiler Error

C

Garbage Value

The correct answer is B. Question 11 Assume that the size of char is 1 byte and negatives are stored in 2's complement form #include<stdio.h> int main() { char c = 125; c = c+10; printf("%d", c); return 0; } Run on IDE A

135

B

+INF

C

-121

D

-8

Tha correct answer is C.

Question 12 #include <stdio.h> int main() { if (sizeof(int) > -1) printf("Yes"); else printf("No"); return 0; } Run on IDE A

Yes

B

No

C

Compiler Error

D

Runtime Error

The correct answer is B. Question 13 Suppose n and p are unsigned int variables in a C program. We wish to set p to nC3. If n is large, which of the following statements is most likely to set p correctly? A

p = n * (n-1) * (n-2) / 6;

B

p = n * (n-1) / 2 * (n-2) / 3;

C

p = n * (n-1) / 3 * (n-2) / 2;

D

p = n * (n-1) * (n-2) / 6.0;

The correct answer is B. Question 14 Output of following program? #include<stdio.h> int main() {

float x = 0.1; if ( x == 0.1 ) printf("IF"); else if (x == 0.1f) printf("ELSE IF"); else printf("ELSE"); }

A

ELSE IF

B

IF ELSE

C The correct answer is A. 15. What is the size of an int data type? ● ● ● ●

A. 4 Bytes B. 8 Bytes C. Depends on the system/compiler D. Cannot be determined.

The correct answer is C. 16. Which data type is most suitable for storing a number 65000 in a 32-bit system? ● ● ● ●

A. short B. int C. long D. double

The correct answer is A. 17. Which of the following is a User-defined data type? ● ● ● ●

A. typedef int Boolean; B. typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays; C. struct {char name[10], int age}; D. All of the mentioned

The correct answer is D. 18. 1. Comment on the output of this C code? int main() {

int a[5] = {1, 2, 3, 4, 5}; int i; for (i = 0; i < 5; i++) if ((char)a[i] == '5') printf("%d\n", a[i]); else printf("FAIL\n"); } ● ● ● ●

A. The compiler will flag an error B. Program will compile and print the output 5 C. Program will compile and print the ASCII value of 5 D. Program will compile and print FAIL for 5 times

Answer: Option D Explanation: The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only. Output: $ cc pgm1.c $ a.out FAILED FAILED FAILED FAILED FAILED

What will be output when you will execute following c code? 19.

#include<stdio.h> int main(){ int a= sizeof(signed) +sizeof(unsigned); int b=sizeof(const)+sizeof(volatile); printf("%d",a+++b); return 0; } Choose all that apply: 10 (B) 9 (C) 8 (D) Error: Cannot find size of modifiers (E) Error: Undefined operator +++ (A)

The correct answer is C.

What will be output when you will execute following c code?

#include<stdio.h> int main(){ signed x,a; unsigned y,b; a=(signed)10u; b=(unsigned)-10; y = (signed)10u + (unsigned)-10; x = y; printf("%d %u\t",a,b); if(x==y) printf("%d %d",x,y); else if(x!=y) printf("%u %u",x,y); return 0; } Choose all that apply: 10 -10 0 0 10 -10 65516 -10 (C) 10 -10 10 -10 (D) 10 65526 0 0 (E) Compilation error (A) (B)

The correct answer is D.

Related Documents


More Documents from ""