In the code fragment below, what are the legal data types for the variable "answer"? (Multiple answers : Choose all that apply )
byte b = 1;
char c = 2;
short s = 3;
int i = 4 ;
float f = 5f;
answer = b * c * s * i * f;
| a. |
byte |
|
| b. |
char |
|
| c. |
short |
|
| d. |
int |
|
| e. |
float |
|
| f. |
double |
|
| g. |
long |
the legal data types for the variable "answer" are float double
float
double
Answer:
In the code fragment below, what are the legal data types for the variable "answer"? (Multiple...
2. Give the minimum size of each of the following C++ types, assuming that char values occupy one byte, short values occupy two bytes, int and float values occupy four bytes, double and long values occupy eight bytes, and pointers occupy four bytes. a) union u type ( double a[3]; int *b; char c[10] b) struct s1type float *d [2]; long e[4] char f[6] short *gi c) struct s2 type ( s1_type s; u type u [2]; int *h[3]; short...
Choose the right data types for all variables mentioned in the following code fragment (all four variables have different data types): int / String / char / double pos = 5.1; text = "hello world"; middle = text.charAt(( )pos);
Give the minimum size of each of the following C data structures, assuming that char values occupy byte, int and float values occupy four bytes, double values occupy eight bytes, and pointers occupy bytes. (a) char str[] = "Curly": (b) double *a[4][4]: (c) char *str[3] = {"Moe", "Larry", "Curly"}: (Include the space occupied by the string literals in your answer.) (d) union { int a: char b: float c[4]: }u: (e) struct { int a: char b: float c[4]: }s:...
4. Consider the following declarations ; char c = ‘a’; byte b = 1; short s = 2; int i = 3; long l = 4; float f = 5.0f; double d = 6.0; Indicate the value which is assigned to the LHS of the assignment statement in each of the following. a. i = b + 2 * s / 2 + i; b. i = (b + 2 * s) / (2 + i); c. i += (b...
Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...
5. (12 points) Consider the following code fragment (part of a program): int index 3; String dna "ACTGTCA char nucleotide dna.charAt (index); Matching: For each term below, write the letter of the ONE choice that best matches the term. Data types Variables Literals Object Method ーParameter nde x a. coumt, nucleotide, and d b. 3 and "ACTGTCA c. int, char, and String d. index e. charAt f. dna na 6. (10 points) a. Wrte a statement that assigns true to...
Which of the following types can be safely compared using the == operator? A- string b- float c- double d- Char 2- What will be stored in variable i after the following statement is executed? int i = (int) Math.sqrt(5);
Consider the two variables in the following C-like (not C) code. Assume that both types of long and int use 32 bits. Do the variable a and b have equivalent type under name type equivalence? What if under structure type equivalence? 0 struct {char c1[4],c1; int i;} a; struct {char c1[2],c2[3]; long l;} b;
Lab 8 CS102 Lab 8 Hands on programming with Pointers The goal of this lab exercise is to apply the knowledge of pointers and File input output operations. Program 1 Short description: Declare, initialize and use pointers for different data types. Detailed Description: Declare 4 variables of type's int, float, double and char respectively and initialize them to some logically correct values. Declare pointers to all these variables. Initialize the pointers to point to these variables respectively Print the values...
Consider the code fragment (assumed to be in a program in which all variables are correctly defined): int num1, num2; double answer; // program gets num1 and num2 from user, and values received // are always non-zero ints between -100 and +100 (code not shown) ... // compute precise quotient: answer = static_cast<double>( num1 / num2 ); After the assignment statement the variable answer, will hold the most precise quotient possible, accurate to several digits to the right of the...