Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Based on below c program out put answers there two questions a) Is the displayed

ID: 3915159 • Letter: B

Question


Based on below c program out put answers there two questions a) Is the displayed value for variable a what you think it should be? Explain the difference in displayed output for b and c in terms of the assigned data types. Be specific.
b, Explain the difference in displayed output for d when %f is used instead of %d. Be specific.








Code: #include int main char a-127,b; unsigned char c; int d-7697264 b- a*2; c a*2 printf( "a-0d b_0d c-Odln",a,b,c); printf("d-%d d %f n",d,d); printf("&d-;%sin",&d;); return 0 #include«stdio.h> int main() char a-127,b; unsigned char c; int d-7697264; b a*2 C- a 2 printf( "a %d b2%d c2%d " , a,b,c); printf("d-%d d %f ",d,d); printf("&d-;%s ",&d;); return ?; Output: hadoop@ubuntu: $ /a.out a 127 b -2 c 254 &d-psu;

Explanation / Answer

a) In this program variable a is declared as character.

But initialized with integer 127. In c, a integer assigned to the character variable is a ASCII code. Here 127 ASCII code is equal to delete. So, the actual value of c is "delete" but c is unable hold the value.

Here b is declared as char and c is declared as unsigned char.

signed typed values are stored in 2's complement internally, but unsigned typed values are stored normally. So , the value of b is 127*2=254 that is in 2's complement=-2 and the value of c is 254 as the output. The basic difference b/w the values b and c is ineternal representation of values of char and unsigned char.

b) The variable d is declared and initialized with integer data.

     %d - is specified to display the content of inetger variable.

    %f   -is used to to display the content of float or double variable.

if %d is specified the printf() expects the next argument is integer.So, the %d specifier prints the value of variable d correctly.

Here %f is specified for integer variable d, but the printf() expects the float or double type variable argument. So, the action is undefined and prints 0.000000 value.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote