Script started on Mon Sep 21 17:26:24 2026 Restored session: Wed Sep 16 18:45:02 EDT 2026 macbook:logs> cd ../programs/C_ch3 macbook:C_ch3> cd .. macbook:programs> cat ~/Desktop/q7 What is wrong with this code? int n; scanf("%d", n); macbook:programs> cd C_ch4 cd: no such file or directory: C_ch4 macbook:programs> mkdir C_ch4 macbook:programs> cd C_ch4 macbook:C_ch4> vi unary_and_binary.c macbook:C_ch4> gcc unary_and_binary.c macbook:C_ch4> cat unary_and_binary.c #include int main() { int i; i = 3 + +3; printf("i is %d\n", i); return 0; } macbook:C_ch4> ./a.out i is 6 macbook:C_ch4> cd ../C_ch5 macbook:C_ch5> grep 6d *c expr.c: printf("%6d %c", expr2.c: printf("%6d %c", macbook:C_ch5> cat expr.c // expr1 : expr2 expr3 // Conditional operators // "?" followed by ":" // // expr1? expr2:expr3; // this means // if expr1 is true then // expr2 // else // expr3 #include #define n 6 int main() { int a[n] = {1, 2, 3, 4, 5, 6}; int i; for (i=0; i gcc expr.c macbook:C_ch5> ./a.out 1 2 3 4 5 6 macbook:C_ch5> cat expr2.c // expr1 : expr2 expr3 // Conditional operators // "?" followed by ":" // // expr1? expr2:expr3; // this means // if expr1 is true then // expr2 // else // expr3 #include #define n 6 int main() { int a[n] = {101, 102, 103, 104, 105, 106}; int i; for (i=0; i gcc expr2.c macbook:C_ch5> ./a.out 101 102 103 104 105 106 macbook:C_ch5> echo logical op like if (cond1 || cond2) zsh: no matches found: (cond1 || cond2) macbook:C_ch5> echo "it means that if either cond1 or cond2 is true" it means that if either cond1 or cond2 is true macbook:C_ch5> echo " then do the body of the id" then do the body of the id macbook:C_ch5> echo " then do the body of the if" then do the body of the if macbook:C_ch5> echo "logical op like if (cond1 && cond2)" logical op like if (cond1 && cond2) macbook:C_ch5> echo "it means that if both cond1 and cond2 are true" it means that if both cond1 and cond2 are true macbook:C_ch5> echo " then do the body of the if" then do the body of the if macbook:C_ch5> macbook:C_ch5> echo "bitwise operations apply to the values" bitwise operations apply to the values macbook:C_ch5> cat binary.txt unsigned binary decimal hex 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F macbook:C_ch5> cat bit_examples.txt 9 10 decimal 1001 AND 1010 1001 1010 ---- 1000 = 8 decimal 1001 OR 1010 1001 1010 ---- 1011 = 11 decimal 1001 XOR 1010 1001 1010 ---- 0011 = 3 decimal a b XOR ------- 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 0 x=9,y=10,z=0 z=x&y; z is 8 z=x|y; z is 11 z=x^y; z is 3 z=x<<1; z is 18 z=y>>2; z is 2 z=~x; z is -10 x is 9 which is 1001 binary y is 10 which is 1010 binary shift x to the left by 1 bit, we get 10010 = 1*2^4 + 0 + 0 + 1*2^1 + 0 = 16 + 2 = 18 shift y to the right by 2 bits, we get 0010 = 2 x is 0..01001 binary, when we invert (NOT) the bits, we get 1..10110 z=~2; z is -3 or fffffffd in hex 2 is 0..0010 in binary, when we invert (NOT) the bits, we get 1..1101 -1 is 1..1111 do the 1's comp: 0..0000 to get 2's comp we add 1 to 1's comp: 0..0000 + 1 = 0..0001 in 2's complement, what is the 4-bit value 1000? 3 is 0011 in binary. What is -3? 1's comp 1100, add 1: 1101, which is -3 macbook:C_ch5> macbook:C_ch5> cat /Users/mweeks/Desktop/csc3320_Fall2026/programs/asdfghjkl Truth table AND a b c c = a AND b 0 0 | 0 0 1 | 0 1 0 | 0 1 1 | 1 OR a b c c = a OR b 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 1 macbook:C_ch5> exit Saving session... ...saving history...truncating history files... ...completed. Deleting expired sessions...none found. Script done on Mon Sep 21 18:48:41 2026