What values are left in the variables after executing the following C sif (d) unsigned char u ; signed char s ; u - S = (unsigned char) -128 ; (signed char) +128 ; ulv odial (1
What values are left in the variables after executing the following C sif (d) unsigned char u ; signed char s ; u - S = (unsigned char) -128 ; (signed char) +128 ; ulv odial (1
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Expert Solution
Explanation
1) We have C code in question which does below steps
- It declare a unsigned char variable u
- It declare a singed char variables s;
- It assign value to variable u
- assign value is negative but type casted to unsigned char
- It assign value to variable s
- assign a positive value but type casted to signed char
2) Type casting is basically a process in C in which we change a variable belonging to one data type to another one.
- An unsigned type can only represent positive values (and zero) where as a signed type can represent both positive and negative values (and zero).
- In the case of a 8-bit char this means that an unsigned char variable can hold a value in the range 0 to 255 while a signed char has the range -128 to 127.
3) type casting convert -128 value to unsigned char, so it is converted into a positive number where negative signed is ignored. So value of u becomes 128
- u = (unsigned char) -128;
- u = 128
4) When we convert 128 value to signed char it converted into a negative number where negative signed is added. So value of s becomes -128
- s = (signed char) +128;
- s = -128
Step by step
Solved in 4 steps with 1 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY