Question

(4) 1. Simplify the following assignments/calculations if possible: a. a = 0; b = 0; c...

(4) 1. Simplify the following assignments/calculations if possible:

a. a = 0; b = 0; c = 0; d = 0; _____________________________

b. n1 = n1 % n2; _____________________________

c. n3 += 1; _____________________________

d. n4 = n5 / n4; _____________________________

2. Suppose that the statement x = 12; has already been done. What values will the following printf statements output assuming that the statements are done in the following order:

a. printf("%d\n", ++x); __________ b. printf("%d\n", x); __________ c. printf("%d\n", x--); __________ d. printf("%d\n", x); __________

Homework Answers

Answer #1

(4) 1.

(a) a=b=c=d=0; (This is a multiple assignment statment, and associativity is from right to left, 0 assigned to d first,value of d(0) is assigned to c ,and c to b, and b to a)

(b) n1%=n2 ; ( x=x%y is same as x%=y)

(c) n3++ or ++n3 ( n3 += 1, n3=n3+1, the same is done by increment operator, which increments the value of variable by 1)

(d) n4=n5/n4

2) ( a) 13 //initially x=12, then ++x , its is preincrement operator, value is first incremented and then used inside the expression. so x is incrementd to x=13 and that value will be printed.

(b) 13 // the value in the previous epression is x=13, so 13 will be printed.

(3) 13 //x=13 then x-- (its post decrement operator,value is first used in a expression and then decremented. So value will be printed first i.e 13, then its decremented. x=12

(d)12 // print the value of x, which is 12 (set in the previous expression)

Know the answer?
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
Similar Questions
The following Verilog module implements module xyz(In,C,Out); input In,C; output Out; wire x,y,In1,Out1; nand n1 (x,In,...
The following Verilog module implements module xyz(In,C,Out); input In,C; output Out; wire x,y,In1,Out1; nand n1 (x,In, C), n2 (y,In1,C), n3 (Out,x,Out1), n4 (Out1,y,Out); not nt (In1,In); endmodule a 2x1 multiplexor b D latch c D flip-flop d RS flip-flop e JK flip-flop
1. Identify and correct the errors in each of the following statements: a) for (a =...
1. Identify and correct the errors in each of the following statements: a) for (a = 25, a <= 1, a--); {printf("%d\n", a);} b) The following code should print whether a given integer is odd or even: switch (value) {case (value % 2 == 0):puts("Even integer");case (value % 2 != 0):puts("Odd integer");} c) The following code should calculate incremented salary after 10 years: for (int year = 1; year <= 10; ++year) {double salary += salary * 0.05;}printf("%4u%21.2f\n", year, salary);...
Hint: it is sufficient to show A implies B, B implies C, C implies D, and...
Hint: it is sufficient to show A implies B, B implies C, C implies D, and D implies A, as repeated application of the hypothetical syllogism will give you A iff B iff C iff D. Using the definitions of odd and even show that the following 4 statements are equivalent: n2 is odd 1 − n is even n3 is odd n + 1 is even
1. Write a program to: Prompt the user to input an integer, a double, a character,...
1. Write a program to: Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single line separated by a space. Add a statement to also output in reverse. Add a statement to cast the double to an integer, and output that integer. 2. 2. Choose the statement(s) that generate(s) this output: I wish you were here a. printf("I wish", "you were here"); b....
Question Rewrite the following C program using switch-case statement. and give me an output please use...
Question Rewrite the following C program using switch-case statement. and give me an output please use printf and scanf #include<stdio.h> int main(void) {      int semester;           printf("What is your Studying Level (1-8)?> ");      scanf("%d" , &semester);      if(semester == 1 || semester == 2)           printf("Your are a freshman!\n ");      else if(semester == 3 || semester == 4)           printf("Your are sophomore!\n ");      else if(semester == 5 || semester == 6)           printf("Your are...
(5 pts.) Consider the C program below. Recall that fflush() just forces the printed value to...
(5 pts.) Consider the C program below. Recall that fflush() just forces the printed value to be output immediately. (For space reasons, we are not checking error return codes, so assume that all functions return normally.) int main () {    if (fork() == 0) {        if (fork() == 0) {           printf("3"); fflush(stdout);        }        else {           pid_t pid; int status;           if ((pid = wait(&status)) > 0) {                  printf("4"); fflush(stdout);           }        }...
Provide a complete solution to the following problem using the C++ language in a SINGLE file...
Provide a complete solution to the following problem using the C++ language in a SINGLE file with a .cpp file extension. READ THE ENTIRE QUESTION (AND THE EXAMPLE) CAREFULLY BEFORE DEVELOPING YOUR SOLUTION! Design the code for a class called Pi, which will be used to encapsulate the value of pi stored as a string. (example ONLY) "3.141592654" | |_ _ _ _| whole number portion_| |_ _ _ _ _fractional portion (9 digits) The Pi class has the following...
1.) 2-bit binary numbers represent the values 0..3 with the following encoding: Encoding [1:0] Value 0...
1.) 2-bit binary numbers represent the values 0..3 with the following encoding: Encoding [1:0] Value 0 0 0 0 1 1 1 0 2 1 1 3 Develop the simplest Sum-of-Products equation possible that, when given two 2-bit binary numbers X[1:0] and Y[1:0], will output whether the value of X is greater than the value of Y. 2.) Assume that we have already implemented the solution to problem #1 as a module “isGreater(F, X, Y)” in Verilog, and cannot change...
SF = square feet of the house PY: 0 = no pool, 1 = pool BY:...
SF = square feet of the house PY: 0 = no pool, 1 = pool BY: 0 = not made of bricks, 1 made of bricks There are three neighborhoods N1, N2 and N3 y = house price Regression Statistics Multiple R 0.91 R Square 0.84 Adjusted R Square 0.83 Standard Error 20,949.15 Observations 301.00 ANOVA df SS MS F Significance F Regression 4.00 667,427,645,418.08 166,856,911,354.52 380.20 0.00 Residual 296.00 129,904,621,849.66 438,866,965.71 Total 300.00 797,332,267,267.74 Coefficients Standard Error t Stat...
Consider the following variable definitions: char a, *b, *c; int d[2], *e; int i, *j; How...
Consider the following variable definitions: char a, *b, *c; int d[2], *e; int i, *j; How many total bytes does this code allocate for variables?  Assume a 32-bit representation for integer and pointer values. a     sizeof(char) b     sizeof(char *) c     sizeof(char *) d    2*sizeof(int) e     sizeof(int *) i     sizeof(int) j     sizeof(int *) Total number of bytes ? What is the output of the following piece of code? (Use the above variable definitions). j = &i; *j = 50;                      /* i = 50 */ e = &d[0]; *e...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT