Questions 3

  1. What is the option that instructs the gcc compiler to print out all warnings?
    Hints:
    GCC: run the command gcc --help=warnings | grep -i 'enable.*warning'.
    Clang: run the command clang --help | grep -i 'enable.*warning' and try to figure out.
  2. Name the comparison operators in C.
  3. Rewrite this piece of code, (a>b?a:b), using the if statement.
  4. If you use mathematical functions from complex.h, do you need to link your program with -lm option?
    Hint: man complex|grep '\-lm'.
  5. What will the following piece of code print?
    int i=1; printf("%i\n",i); printf("%i\n",i++); printf("%i\n",++i);
    
    Explain.
    How about
    int i=1; printf("%i %i %i\n",i,i++,++i);
    
    Hint: compile with -Wall.
  6. Rewrite the loop while(condition)body using the for loop.
  7. Rewrite the loop for(init;cond;inc)body using the while loop.
  8. Rewrite the loop do body while(condition); using the for loop.
  9. Is this a valid C-code?
    if(0) printf("0 is true\n");
    else  printf("0 is false\n");
    if(7) printf("7 is true\n");
    else  printf("7 is false\n");
    
    Hint: Wikipedia → C syntax → Selection statements.
  10. Does C have a boolean type (that is, a type having one of the two values, "true" or "false") type?
    Hint: Wikipedia → Boolean data type →C.