Practice Problems

Intro material

Notice when you get compile errors (when gcc gives you an error)
vs. errors that crash the program (run-time errors)
vs. logical errors (compile and run fine but problem with your code)

  1. What happens when you put a semi-colon after the main function?
    		int main( );
    		{
    		}
    	
  2. What happens when you mis-spell main?
  3. What happens if you use printf but forget to include stdio.h?
  4. Find and correct the errors in the following code:
    		#include (stdio.h)
    		int main( void );
    		{
    			print( "Hello" )
    			return 0;
    		{
     	
  5. Write a program with ONE printf statement to produce the following output:
    	*
    	**
    	***
    	****
    	
  6. What's the difference between // and /* ?
  7. When compiling, what is the name of the executable file that is created?
  8. What does the -o option do when compiling?
  9. Write the command to compile a program named x.c and create the executable named go.
  10. Approximately what is the line #include <stdio.h> at the top of a C source file for?
  11. What are some uses for comments?
  12. Why is indentation important? How carefully does the compiler pay attention to it?

Variables

  1. Code the variable declarations for each of the following:
    	* a character variable named option set equal to the letter T
    	* an integer variable named sum initialized to zero
    	* a floating point variable named product initialized to 1
       
  2. Can variable names have spaces in them?
  3. Can variable names begin with the underscore character?