←to practical programming

Questions "stdio"

  1. What are standard input, standard output and standard error in the context of POSIX programming?
    Hints: apropos standard | grep streams; man stdin; Wikipedia: standard streams.

  2. What is EOF in the context of scanf?
    Hints: man scanf and search for EOF; wikipedia "end of file".

  3. Where to does the function printf write?

  4. Where from does the function scanf read?

  5. How do you redirect the standard output of a program to a file?

  6. How do you send the content of a file into a program's standard input?

  7. How do you connect the standard output of a program to the standard input of another program?
    Hint: GNU make manual: automatic variables, implicit variables, implicit rules.

  8. Suppose your main function, contained in the file main.c, calls the functions foo and bar which are contained correspondingly in the files foo.c and bar.c. Which of the following makefiles will correctly compile and link your program into the executable file main after the command make?

    1. main: main.o foo.o bar.o
      
    2. main: foo.o main.o bar.o
      
    3. main: foo.o main.o bar.o
      	cc foo.o main.o bar.o -o main
      
    4. main: main.o foo.o bar.o
      	$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
      
    5. main: main.o foo.o bar.o
      main.o: main.c
      foo.o: foo.c
      	cc -c $^ -o $@
      bar.o: bar.c
      
    6. main: main.o foo.o bar.o
      	cc main.o foo.o bar.o -lm -o main
      main.o: main.c
      	cc -c main.c
      foo.o: foo.c
      	cc -c foo.c
      bar.o: bar.c
      	cc -c bar.c
      
    7. obj = main.o foo.o bar.o
      main: $(obj)
      
  9. Suppose there is the following preprocessor directive at the beginning of the file,
    #define PI 3.1415927
    
    what is the effect of it?
    1. The compiler creates a variable PI of type double and stores the value 3.1415927 in it.
    2. All occurences of the token 'PI' in the file are substituted with the token '3.1415927'.