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

Understanding Operators This assignment is to help you understand the various as

ID: 3877194 • Letter: U

Question

Understanding Operators

This assignment is to help you understand the various assignment and operators in the C language. First try to understand and answer in the comment field by hand. Then cut and paste this code to the IDE and compile/link and execute the code in the debugger to “validate” your answers. If you got your answer wrong, use the computer debugger and lecture slides to understand how the operator works.

Be aware that you may see these on a test.

Submit only the C-code and as Hw1.c. Include a header comment which contains your name. Minus 5 points if this is not followed.

When required in the comment field 0x, answer with the value in hexadecimal.

Be sure to fix any compilation errors…. You are allowed to put newlines between the statements to help you step through the code using the debugger. For example:

Original code: j=41; i=j++; //i=

Newline: j=41;

                  i=j++; //i=

#include <math.h>

void main()

{

        char j, i;

        unsigned char uj, ui; //char are byte size identifiers

        float fj = 10.0, fi = 10.00977, fd;

        j=-21; i=-j;                    // i=

        ui=127; i=++ui;         // ui= i=

        ui=0; --ui;                     // ui=

        j=41; i=j++;                    // i=

        j=41; i=++j;                    // i=

        j=41; i=(j++);          // i=

        j=41; i=j--;                    // i=

        j=41; i= ++j + 42 + j;         // i=

        j=41; i= j + 42 + j++;         // i=

        j=41; i= ++j + 42 + j;         // i=

        ui=142; i=ui;                   // i=

j=41; i=j + 42 + (j++); // i=

        j=41; i=j + 42 + (++j); // i=

j=41; i=(++j) + 42 + j; // i=

        j=41; i=--j;                    // i=

        j=41; i=!j;                     // i=

        i=41; i+=41;                    // i=

        j=41; i=j/2;                    // i=

        j=41; i=j%2;                    // i=

        uj=41; ui=uj<<1;                // ui=

        uj=40; ui=uj>>1;                // ui=

        j=0xBD; i=~j;                   // i= 0x

        j=0xFF; i=j&&0x42;              // i= 0x

        j=0xFF; i=j&0x42;               // i= 0x

        j=0xAA; i=j^0xE8;               // i= 0x

        j=0xFF; i=j|0x42;               // i= 0x

        j=42 i=!j;                      // i=

        fd=fi;                          // i=

        //fabs() is a floating point absolute function,

// just the get rid of the negative value

fd=fabs(fj--fi);                // i=

        i=(fd != 0.00977);              // i=

        i=(fd == 0.00977);              // i=

        i>>=0;          // i=

        i&= !0;         // i=

}

       

       

  

Explanation / Answer

Find the Errors free and value set C code.

#include <math.h>

float fabs(float f){
    if(f < 0){
        return(-1 * f);
    }
    else
        return(f);
}
int main(){
    char j, i;
    unsigned char uj, ui; //char are byte size identifiers
    float fj = 10.0, fi = 10.00977, fd;

    j=-21; i=-j;                 // i= 21
    ui=127; i=++ui;              // ui=128 i=-128
    ui=0; --ui;                  // ui=255
    j=41; i=j++;                 // i=41
    j=41; i=++j;                 // i=42
    j=41; i=(j++);               // i=41
    j=41; i=j--;                 // i=41
    j=41; i= ++j + 42 + j;       // i=126
    j=41; i= j + 42 + j++;       // i=125
    j=41; i= ++j + 42 + j;       // i=126
    ui=142; i=ui;                // i=-114
    j=41; i=j + 42 + (j++);      // i=125
    j=41; i=j + 42 + (++j);      // i=126
    j=41; i=(++j) + 42 + j;      // i=126
    j=41; i=--j;                 // i=40
    j=41; i=!j;                  // i=0
    i=41; i+=41;                 // i=82
    j=41; i=j/2;                 // i=20
    j=41; i=j%2;                 // i=1
    uj=41; ui=uj<<1;             // ui=82
    uj=40; ui=uj>>1;             // ui=20
    j=0xBD; i=~j;                // i= 0x42D
    j=0xFF; i=j&&0x42;           // i= 0x1D
    j=0xFF; i=j&0x42;            // i= 0x42D
    j=0xAA; i=j^0xE8;            // i= 0x42D
    j=0xFF; i=j|0x42;            // i= 0xFFFFFFFFD
    j=42; i=!j;                  // i=0
    fd=fi;                       // i=0
    //fabs() is a floating point absolute function,
    // just the get rid of the negative value
    fd=fabs(fj-fi);             // i=0
    i=(fd != 0.00977);           // i=1
    i=(fd == 0.00977);           // i=0
    i>>=0;                       // i=0
    i&= !0;                      // i=0
    return(0);
}