Question

10.) (8) Indicate which of the following assignment statements are legal if x is an int variable and y is a float variable. Show what is stored in the receiving variables if the statement is correct: а, у х: c. y (float) x; d. x (int) y r++ A homeowner would like to calculate the idla of a rectanglefor C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer is as follows :

All the given statements are legal in C++.

Let x = 10 i.e. int

and y = 20.2 i.e. float

The output stored in the recieving variables is as follows :

a) y = x

Here the variable x has int value i.e. 10 passes to variable y i.e. 10.

So y stores only 10.

b) x = y

int this only int part of float variable y i.e. 20 only from 20.2 is transferred to ariable x.

So x stores the 20 only.

c) y = (float) x

here the variable x is converted to float and store the result to float variable y.

now the x contain 10 but in float it is equal to 10.0.

So the y contains 10.0 or we can say only 10.(both are same).

d) x= (int) y

here float variable is converted to int but part without decimal is conerted.

So now float variable y has 20.2 and after conversion it gets only 20 as integer i.e. store in variable x.

So the x stores 20 only.

if there is any query please ask in comments...

Add a comment
Know the answer?
Add Answer to:
for C++ 10.) (8) Indicate which of the following assignment statements are legal if x is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C language not C++ 1. Write the statements to do the following: (2 pts) a. Define...

    C language not C++ 1. Write the statements to do the following: (2 pts) a. Define a struct with member variables width, height, topleft x, topleft y all floats). Use a tag to call it Rectangle. b. Declare a variable struct type Rectangle 2. Consider the following variables: struct int x; float y; char zi var1; union nt x; float y; char[20] z;) var2 f float and int are stored using 4 bytes each, what is the size (in bytes)...

  • C++ help! #4,6,7 c) no-test d) loop-test e) None of these 1. Which of the following...

    C++ help! #4,6,7 c) no-test d) loop-test e) None of these 1. Which of the following variable names is invalid? a) numstudents b) 2Darray c) studentHame d) test Grade 祁.which of the following conditions is true ifX has a value of 10 and T has a value of 20? None of these 2. In Ca4, the operator indicates: a) subtraction b) negation c) equality e) None of these . What are the final values of z and y after the...

  • Consider the following in C int main() { float x = 3.14, *p = &x; int...

    Consider the following in C int main() { float x = 3.14, *p = &x; int r, a = 2, b[] = {5, 6, 7}; <more code here> r = Foo(x, p, &a, b) <more code here> } int Foo(float x,float y, int *z, int *w) { <Foo's code goes here> } statement in Foo result (assigned value) modify Foo's AF variables modify main's AF variables statement in Foo result (assigned value) modify Foo's AF variables modify main's AF variables...

  • 1.   What will be the value of x after the following code is executed? int x...

    1.   What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x += y; } A.   90 B.   110 C.   210 D.   This is an infinite loop 2.   If a superclass has constructor(s): A.   then its subclass must initialize the superclass fields (attributes). B.   then its subclass must call one of the constructors that the superclass does have. C.   then its subclass does not inherit...

  • Specify whether each of the following errors is a syntax error, a runtime error or a...

    Specify whether each of the following errors is a syntax error, a runtime error or a logic error: a. using single quotes where command needs double quotes _____ b. dollar and cents amount on a bill is not formatted correctly _____ c. divide a number by zero _____ (8) Evaluate the following expressions: a. fabs (-25.2) b. pow(4.0, 3.0) c. squareroot (400) d. fabs (8.2) e. squareroot (-400) f. floor(-6.7) g. floor(6.7) h. ceil(-4.1) (4) Indicate which of the following...

  • 4. Using cin, Allocating Memory, and Writing Assignment Statements cin, Memory Allocation, and Assignment Statements show...

    4. Using cin, Allocating Memory, and Writing Assignment Statements cin, Memory Allocation, and Assignment Statements show the variable name and value of each statement 19. double x = 5.0; int y = 4; x= x + y 14; 20. double x = 5.0; int y = 4; y = x + y/4; 21. int count = 0; cout << ++count << endl; cout << count++ << endl; cout << count << endl;

  • In the following C program, indicate the variable type (global, local, or static local), the lifetime...

    In the following C program, indicate the variable type (global, local, or static local), the lifetime (when the program is run or when the function is called), and the memory allocation (from stack or from heap) for each variable (x, y, z, and w) defined in the program. int w; void fun (int x) { int y; static float z; ... } void main() { fun(w); }

  • QUESTION 1 Given two double variables named x and y, which of the following statements could...

    QUESTION 1 Given two double variables named x and y, which of the following statements could you use to initialize both variables to a value of 0.0? a. x | y = 0.0; b. x = y = 0.0; c. x, y = 0.0; d. none of the above 1 points    QUESTION 2 When you use a range-based for loop with a vector, you a. can avoid out of bounds access b. must still use a counter variable c....

  • 1. (2 points each) Indicate whether each of the following statements are valid or invalid function...

    1. (2 points each) Indicate whether each of the following statements are valid or invalid function declarations (prototypes) by highlighting your answer choice (Are they syntactically correct?). a) double change( X, Y);                           answer:                Valid       Invalid b) char sign(double x);                               answer:                Valid       Invalid c) int max(int x, int y, int z)                         answer:                Valid       Invalid 2. (2 points each) Indicate whether each of the following statements are syntactically valid or invalid function headers by highlighting your answer choice. a) double change( X,...

  • QUESTION 1 What will be displayed as a result of executing the following code? int   x...

    QUESTION 1 What will be displayed as a result of executing the following code? int   x = 5, y = 20; x += 32; y /= 4; cout <<"x = " << x <<"y = " << y; A. x = 32, y = 4 B. x = 9, y = 52 C. x = 37, y = 5 D. x = 160, y = 80 8 points    QUESTION 2 What will be the displayed when the following code...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT